lib/lazier/datetime.rb in lazier-3.3.8 vs lib/lazier/datetime.rb in lazier-3.3.9

- old
+ new

@@ -15,22 +15,22 @@ # @see Settings#setup_date_names # # @param short [Boolean] If return the abbreviated representations. # @return [Array] Return string representations of days. def days(short = true) - ::Lazier.settings.date_names[short ? :short_days : :long_days].collect.with_index {|label, index| + ::Lazier.settings.date_names[short ? :short_days : :long_days].map.with_index {|label, index| {value: (index + 1).to_s, label: label} } end # Returns strings representations of months. # @see Settings#setup_date_names # # @param short [Boolean] If return the abbreviated representations. # @return [Array] Return string representations of months. def months(short = true) - ::Lazier.settings.date_names[short ? :short_months : :long_months].collect.with_index {|label, index| + ::Lazier.settings.date_names[short ? :short_months : :long_months].map.with_index {|label, index| {value: (index + 1).to_s.rjust(2, "0"), label: label} } end # Returns a range of years. @@ -51,11 +51,11 @@ # @param reference [Fixnum] The ending (or middle, if `also_future` is `true`) value of the range. Defaults to the current year. # @param as_objects [Boolean] If to return years in hashes with `:value` and `label` keys. # @return [Array] A range of years. Every entry is def years(offset = 10, also_future = true, reference = nil, as_objects = false) y = reference || ::Date.today.year - (y - offset..(also_future ? y + offset : y)).collect { |year| as_objects ? {value: year, label: year} : year } + (y - offset..(also_future ? y + offset : y)).map { |year| as_objects ? {value: year, label: year} : year } end # Returns all the availabe timezones. # # @return [Array]All the zone available. @@ -314,12 +314,12 @@ # @param dst_label [String] Label for the DST indication. Defaults to `(DST)`. # @return [Array] A list of names of timezones. def list_all(with_dst = true, dst_label = nil) dst_label ||= "(DST)" - @zones_names ||= { "STANDARD" => ::ActiveSupport::TimeZone.all.collect(&:to_s) } - @zones_names["DST[#{dst_label}]-STANDARD"] ||= ::ActiveSupport::TimeZone.all.collect { |zone| fetch_aliases(zone, dst_label) }.flatten.compact.uniq.sort { |a,b| ::ActiveSupport::TimeZone.compare(a, b) } # Sort by name + @zones_names ||= { "STANDARD" => ::ActiveSupport::TimeZone.all.map(&:to_s) } + @zones_names["DST[#{dst_label}]-STANDARD"] ||= ::ActiveSupport::TimeZone.all.map { |zone| fetch_aliases(zone, dst_label) }.flatten.compact.uniq.sort { |a,b| ::ActiveSupport::TimeZone.compare(a, b) } # Sort by name @zones_names["#{with_dst ? "DST[#{dst_label}]-" : ""}STANDARD"] end # Returns a string representation of a timezone. @@ -382,20 +382,20 @@ # @param zone [ActiveSupport::TimeZone] The zone. # @param dst_label [String] Label for the DST indication. Defaults to `(DST)`. def fetch_aliases(zone, dst_label = "(DST)") matcher = /(#{Regexp.quote(dst_label)})$/ - zone.aliases.collect { |zone_alias| + zone.aliases.map { |zone_alias| [zone.to_str(zone_alias), (zone.uses_dst? && zone_alias !~ matcher) ? zone.to_str_with_dst(dst_label, nil, zone_alias) : nil] } end end # Returns a list of valid aliases (city names) for this timezone (basing on offset). # @return [Array] A list of aliases for this timezone def aliases reference = self.class::MAPPING.fetch(name, name).gsub("_", " ") - @aliases ||= ([reference] + self.class::MAPPING.collect { |name, zone| format_alias(name, zone, reference) }).uniq.compact.sort + @aliases ||= ([reference] + self.class::MAPPING.map { |name, zone| format_alias(name, zone, reference) }).uniq.compact.sort end # Returns the current offset for this timezone, taking care of Daylight Saving Time (DST). # # @param rational [Boolean] If to return the offset as a Rational. \ No newline at end of file