class TimeStep::Calendar
Constants
- DateTimeType
- SYM_360_day
@private
- SYM_365_day
@private
- SYM_366_day
@private
Attributes
calendar[R]
name[R]
tz[R]
Public Class Methods
new(calendar = "standard", tz: nil)
click to toggle source
Construct the object
# File lib/timesteps/timestep_calendar.rb, line 28 def initialize (calendar = "standard", tz: nil) unless calendar.is_a?(String) raise ArgumentError, "argument calendar '#{calendar}' should be string" end @name = calendar case @name.downcase.intern when :standard, :gregorian @calendar = :standard when :proleptic_gregorian @calendar = :proleptic_gregorian when :proleptic_julian, :julian @calendar = :proleptic_julian when :noleap, SYM_365_day @calendar = :noleap when :allleap, SYM_366_day @calendar = :allleap when SYM_360_day @calendar = SYM_360_day end if tz raise "'standard' calendar needed for tz" unless @calendar == :standard case tz when nil when String @tz = TZInfo::Timezone.get(tz) when TZInfo::Timezone @tz = tz else raise "invalid tz specification" end end end
Public Instance Methods
==(other)
click to toggle source
# File lib/timesteps/timestep_calendar.rb, line 67 def == (other) return @calendar == other.calendar end
date2jday(year, month, day)
click to toggle source
# File lib/timesteps/timestep_calendar.rb, line 135 def date2jday (year, month, day) return time_new(year, month, day).jd end
inspect()
click to toggle source
# File lib/timesteps/timestep_calendar.rb, line 63 def inspect "#<TimeStep::Calendar calendar='#{@calendar.to_s}'>" end
jday2date(jday)
click to toggle source
# File lib/timesteps/timestep_calendar.rb, line 114 def jday2date (jday) case @calendar when :standard time = DateTime.jd(jday, 0, 0, 0, 0, Date::ITALY) when :proleptic_gregorian time = DateTime.jd(jday, 0, 0, 0, 0, Date::GREGORIAN) when :proleptic_julian time = DateTime.jd(jday, 0, 0, 0, 0, Date::JULIAN) when :noleap time = DateTime::NoLeap.jd(jday, 0, 0, 0, 0) when :allleap time = DateTime::AllLeap.jd(jday, 0, 0, 0, 0) when SYM_360_day time = DateTime::Fixed360Day.jd(jday, 0, 0, 0, 0) end if @tz time = @tz.to_local(time) end return time end
parse(timespec, format: nil, offset: nil)
click to toggle source
Parses the given representation of date and time in the calendar, and creates an date time instance.
@return [DateTime object]
# File lib/timesteps/timestep_calendar.rb, line 89 def parse (timespec, format: nil, offset: nil) return DateTime.parse_timestamp(timespec, calendar: @calendar.to_s, format: format, tz: @tz, offset: offset) end
time_new(year, month, day, hour=0, min=0, sec=0, offset=0)
click to toggle source
# File lib/timesteps/timestep_calendar.rb, line 93 def time_new (year, month, day, hour=0, min=0, sec=0, offset=0) case @calendar when :standard time = DateTime.new(year, month, day, hour, min, sec, offset, Date::ITALY) when :proleptic_gregorian time = DateTime.new(year, month, day, hour, min, sec, offset, Date::GREGORIAN) when :proleptic_julian time = DateTime.new(year, month, day, hour, min, sec, offset, Date::JULIAN) when :noleap time = DateTime::NoLeap.new(year, month, day, hour, min, sec, offset) when :allleap time = DateTime::AllLeap.new(year, month, day, hour, min, sec, offset) when SYM_360_day time = DateTime::Fixed360Day.new(year, month, day, hour, min, sec, offset) end if @tz time = @tz.to_local(time) end return time end
valid_datetime_type?(time)
click to toggle source
# File lib/timesteps/timestep_calendar.rb, line 71 def valid_datetime_type? (time) return false unless time.is_a?(DateTimeType[@calendar]) case @calendar when :standard return time.start == Date::ITALY when :proleptic_gregorian return time.start == Date::GREGORIAN when :proleptic_julian return time.start == Date::JULIAN else return true end end