lib/parsi-date.rb in parsi-date-0.3.1 vs lib/parsi-date.rb in parsi-date-0.4.0
- old
+ new
@@ -139,15 +139,17 @@
MJD_EPOCH_IN_CJD = 2400001 # :nodoc:
UNIX_EPOCH_IN_CJD = 2440588 # :nodoc:
LD_EPOCH_IN_CJD = 2299160 # :nodoc:
DAYS_IN_MONTH = [nil, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29] # :nodoc:
+ LEAP_REMINDERS = [1, 5, 9, 13, 17, 22, 26, 30].freeze
+
shared_methods = Module.new do
# Returns true if the given year is a leap year of the calendar.
def leap? year
- ((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682
+ LEAP_REMINDERS.include?(year - (year / 33).floor * 33)
end
alias_method :jalali_leap?, :leap?
private
@@ -187,11 +189,11 @@
# Do +year+, +month+, and day-of-month +day+ make a valid Civil Date?
# Returns the corresponding Julian Day Number if they do, nil if they don't.
# Invalid values cause an ArgumentError to be raised.
def _valid_civil? year, month, day # :nodoc:
- return unless year.is_a?(Fixnum) && month.is_a?(Fixnum) && day.is_a?(Fixnum)
+ return unless year.is_a?(Integer) && month.is_a?(Integer) && day.is_a?(Integer)
return civil_to_jd(year, 12, 30) if leap?(year) && month == 12 && day == 30
if 1 <= month && month <= 12 && 1 <= day && day <= DAYS_IN_MONTH[month]
return civil_to_jd year, month, day
else
@@ -745,11 +747,12 @@
alias :jalali :parsi
end
# Returns a Parsi::Date object representing same date in Jalali calendar
def to_parsi
- Parsi::Date.new! ajd, offset
+ Parsi::Date.new! ajd
end
+
alias :jalali :to_parsi
alias :to_jalali :to_parsi
alias :to_persian :to_parsi
end