lib/lazier/datetime.rb in lazier-4.1.0 vs lib/lazier/datetime.rb in lazier-4.2.0

- old
+ new

@@ -45,12 +45,12 @@ # ``` # # # @param offset [Fixnum] The width of the range. # @param also_future [Boolean] If return also future years. - # @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. + # @param reference [Fixnum|NilClass] The ending (or middle, if `also_future` is `true`) value of the range. Defaults to the current year. + # @param as_objects [Boolean] Whether 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)).map { |year| as_objects ? {value: year, label: year} : year } end @@ -78,11 +78,11 @@ end # Returns the Easter (according to Gregorian calendar) date for the year. # @see http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm # - # @param year [Fixnum] The year to compute the date for. Defaults to the current year. + # @param year [Fixnum|NilClass] The year to compute the date for. Defaults to the current year. # @return [Date] The Easter date for the year. def easter(year = nil) year = ::Date.today.year unless year.integer? # Compute using Anonymous Gregorian Algorithm: http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm @@ -136,31 +136,31 @@ end end # Returns the number of months passed between the beginning of the base year and the current date. # - # ```ruby - # DateTime.civil(2013, 6, 1).in_months(2011) - # # => 18 - # ``` + # Example: # - # @param base [DateTime] The base year to start computation from. Default to current year. + # DateTime.civil(2013, 6, 1).in_months(2011) + # # => 18 + # + # @param base [DateTime|NilClass] The base year to start computation from. Default to current year. # @return [Fixnum] Returns the number of months passed between the beginning of the base year and the current date. def months_since_year(base = nil) (year - (base || ::Date.today.year)) * 12 + month end - # Returns the current month number with leading 0. + # Returns the current month number with a leading zero if needed. # - # @return [String] The current month number with leading 0. + # @return [String] The current month number with leading zero if needed. def padded_month month.indexize end # Formats a datetime, eventually looking up also custom formats and/or moving to the current timezone. # @see Settings#setup_date_formats # - # @param format [String] A format or a custom format name to use for formatting. + # @param format [String|NilClass] A format or a custom format name to use for formatting. # @param custom [Boolean] Whether to use custom formats. # @param change_time_zone [Boolean] Whether to move the date to the current timezone. # @return [String] The formatted date. def format(format = nil, custom: true, change_time_zone: false) target = change_time_zone && respond_to?(:in_time_zone) ? in_time_zone : self