Class: Date
- Includes:
- Comparable
- Defined in:
- lib/framework/date.rb,
lib/framework/dateME.rb,
lib/framework/dateOrig.rb,
lib/framework/dateOrig.rb,
lib/framework/date/format.rb,
lib/framework/autocomplete/Date.rb
Overview
It is auto-generated content. Do not do required for this file in your application.
Direct Known Subclasses
Defined Under Namespace
Modules: Format Classes: Infinity
Constant Summary collapse
- MONTHNAMES =
Full month names, in English. Months count from 1 to 12; a month’s numerical representation indexed into this array gives the name of that month (hence the first element is nil).
[nil] + %w(January February March April May June July August September October November December)
- ABBR_MONTHNAMES =
Abbreviated month names, in English.
[nil] + %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
- DAYNAMES =
Full names of days of the week, in English. Days of the week count from 0 to 6 (except in the commercial week); a day’s numerical representation indexed into this array gives the name of that day.
%w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
- ABBR_DAYNAMES =
Abbreviated day names, in English.
%w(Sun Mon Tue Wed Thu Fri Sat)
- DATE_FORMATS =
{ :short => "%e %b", :long => "%B %e, %Y", :db => "%Y-%m-%d", :number => "%Y%m%d" }
- SECONDS_IN_DAY =
:nodoc:
Rational(1, 86400)
- ITALY =
The Julian Day Number of the Day of Calendar Reform for Italy and the Catholic countries.
2299161
- ENGLAND =
The Julian Day Number of the Day of Calendar Reform for England and her Colonies.
2361222
- JULIAN =
A constant used to indicate that a Date should always use the Julian calendar.
Infinity.new
- GREGORIAN =
A constant used to indicate that a Date should always use the Gregorian calendar.
Infinity.new(-1)
- HALF_DAYS_IN_DAY =
:nodoc:
Rational(1, 2)
- HOURS_IN_DAY =
:nodoc:
Rational(1, 24)
- MINUTES_IN_DAY =
:nodoc:
Rational(1, 1440)
- MILLISECONDS_IN_DAY =
:nodoc:
Rational(1, 86400*10**3)
- NANOSECONDS_IN_DAY =
:nodoc:
Rational(1, 86400*10**9)
- MILLISECONDS_IN_SECOND =
:nodoc:
Rational(1, 10**3)
- NANOSECONDS_IN_SECOND =
:nodoc:
Rational(1, 10**9)
- MJD_EPOCH_IN_AJD =
1858-11-17 # :nodoc:
Rational(4800001, 2)
- UNIX_EPOCH_IN_AJD =
1970-01-01 # :nodoc:
Rational(4881175, 2)
- MJD_EPOCH_IN_CJD =
:nodoc:
2400001
- UNIX_EPOCH_IN_CJD =
:nodoc:
2440588
- LD_EPOCH_IN_CJD =
:nodoc:
2299160
Class Method Summary collapse
-
._httpdate(str) ⇒ Object
:nodoc:.
-
._iso8601(str) ⇒ Object
:nodoc:.
-
._jisx0301(str) ⇒ Object
:nodoc:.
- ._parse(str, comp) ⇒ Object
-
._rfc2822(str) ⇒ Object
:nodoc:.
-
._rfc3339(str) ⇒ Object
:nodoc:.
-
._rfc822(str) ⇒ Object
:nodoc:.
- ._strptime(str, fmt) ⇒ Object
-
._xmlschema(str) ⇒ Object
:nodoc:.
-
.civil(y = -4712,, m = 1, d = 1, sg = ITALY) ⇒ Object
Create a new Date object for the Civil Date specified by year
y
, monthm
, and day-of-monthd
. -
.commercial(y = -4712,, w = 1, d = 1, sg = ITALY) ⇒ Object
Create a new Date object for the Commercial Date specified by year
y
, week-of-yearw
, and day-of-weekd
. -
.gregorian_leap?(y) ⇒ Boolean
(also: leap?)
Is a year a leap year in the Gregorian calendar?.
-
.httpdate(str = 'Mon, 01 Jan -4712 00:00:00 GMT', sg = ITALY) ⇒ Object
:nodoc:.
-
.iso8601(str = '-4712-01-01', sg = ITALY) ⇒ Object
:nodoc:.
-
.jd(jd = 0, sg = ITALY) ⇒ Object
Create a new Date object from a Julian Day Number.
-
.jisx0301(str = '-4712-01-01', sg = ITALY) ⇒ Object
:nodoc:.
-
.julian_leap?(y) ⇒ Boolean
Is a year a leap year in the Julian calendar?.
-
.new ⇒ Object
(also: new!)
Create a new Date object for the Civil Date specified by year
y
, monthm
, and day-of-monthd
. -
.once(*ids) ⇒ Object
:nodoc: – restricted.
-
.ordinal(y = -4712,, d = 1, sg = ITALY) ⇒ Object
Create a new Date object from an Ordinal Date, specified by year
y
and day-of-yeard
. -
.parse(str = '-4712-01-01', comp = true, sg = ITALY) ⇒ Object
Create a new Date object by parsing from a String, without specifying the format.
-
.rfc2822(str = 'Mon, 1 Jan -4712 00:00:00 +0000', sg = ITALY) ⇒ Object
:nodoc:.
-
.rfc3339(str = '-4712-01-01T00:00:00+00:00', sg = ITALY) ⇒ Object
:nodoc:.
-
.rfc822 ⇒ Object
:nodoc:.
-
.strptime(str = '-4712-01-01', fmt = '%F', sg = ITALY) ⇒ Object
Create a new Date object by parsing from a String according to a specified format.
-
.today(sg = ITALY) ⇒ Object
Create a new Date object representing today.
- .valid_civil?(y, m, d, sg = ITALY) ⇒ Boolean (also: valid_date?)
- .valid_commercial?(y, w, d, sg = ITALY) ⇒ Boolean
- .valid_jd?(jd, sg = ITALY) ⇒ Boolean
- .valid_ordinal?(y, d, sg = ITALY) ⇒ Boolean
-
.xmlschema(str = '-4712-01-01', sg = ITALY) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#+(n) ⇒ Object
Return a new Date object that is
n
days later than the current one. -
#-(x) ⇒ Object
If
x
is a Numeric value, create a new Date object that isx
days earlier than the current one. -
#<<(n) ⇒ Object
Return a new Date object that is
n
months earlier than the current one. -
#<=>(other) ⇒ Object
Compare this date with another date.
-
#===(other) ⇒ Object
The relationship operator for Date.
-
#>>(n) ⇒ Object
Return a new Date object that is
n
months later than the current one. - #_get_date ⇒ Object
-
#ajd ⇒ Object
Get the date as an Astronomical Julian Day Number.
-
#amjd ⇒ Object
Get the date as an Astronomical Modified Julian Day Number.
-
#asctime ⇒ Object
alias_method :format, :strftime.
-
#ctime ⇒ Object
alias_method :format, :strftime.
-
#cwday ⇒ Object
Get the commercial day of the week of this date.
-
#cweek ⇒ Object
Get the commercial week of the year of this date.
-
#cwyear ⇒ Object
Get the commercial year of this date.
-
#day_fraction ⇒ Object
Get any fractional day part of the date.
-
#downto(min, &block) ⇒ Object
Step backward one day at a time until we reach
min
(inclusive), yielding each date as we go. -
#england ⇒ Object
Create a copy of this Date object that uses the English/Colonial Day of Calendar Reform.
-
#eql?(other) ⇒ Boolean
Is this Date equal to
other
?. -
#gregorian ⇒ Object
Create a copy of this Date object that always uses the Gregorian Calendar.
-
#gregorian? ⇒ Boolean
Is the current date new-style (Gregorian Calendar)?.
-
#hash ⇒ Object
Calculate a hash value for this date.
-
#httpdate ⇒ Object
:nodoc:.
-
#initialize(ajd = 0, of = 0, sg = ITALY) ⇒ Date
constructor
NOTE this is the documentation for the method new!().
-
#inspect ⇒ Object
Return internal object state as a programmer-readable string.
- #iso8601 ⇒ Object
-
#italy ⇒ Object
Create a copy of this Date object that uses the Italian/Catholic Day of Calendar Reform.
-
#jd ⇒ Object
Get the date as a Julian Day Number.
- #jisx0301 ⇒ Object
-
#julian ⇒ Object
Create a copy of this Date object that always uses the Julian Calendar.
-
#julian? ⇒ Boolean
Is the current date old-style (Julian Calendar)?.
-
#ld ⇒ Object
Get the date as the number of days since the Day of Calendar Reform (in Italy and the Catholic countries).
-
#leap? ⇒ Boolean
Is this a leap year?.
-
#marshal_dump ⇒ Object
Dump to Marshal format.
-
#marshal_load(a) ⇒ Object
Load from Marshal format.
-
#mday ⇒ Object
(also: #day)
Get the day-of-the-month of this date.
-
#mjd ⇒ Object
Get the date as a Modified Julian Day Number.
-
#mon ⇒ Object
(also: #month)
Get the month of this date.
-
#new_start(sg = self.class::ITALY) ⇒ Object
Create a copy of this Date object using a new Day of Calendar Reform.
-
#next ⇒ Object
(also: #succ)
Return a new Date one day after this one.
- #next_day(n = 1) ⇒ Object
- #next_month(n = 1) ⇒ Object
- #next_year(n = 1) ⇒ Object
- #old_strftime ⇒ Object
- #prev_day(n = 1) ⇒ Object
- #prev_month(n = 1) ⇒ Object
- #prev_year(n = 1) ⇒ Object
- #rfc2822 ⇒ Object
- #rfc3339 ⇒ Object
- #rfc822 ⇒ Object
-
#start ⇒ Object
When is the Day of Calendar Reform for this Date object?.
-
#step(limit, step = 1) ⇒ Object
Step the current date forward
step
days at a time (or backward, ifstep
is negative) until we reachlimit
(inclusive), yielding the resultant date at each step. - #strftime(fmt) ⇒ Object
- #to_date ⇒ Object
- #to_datetime ⇒ Object
- #to_formatted_s(type) ⇒ Object
-
#to_s ⇒ Object
Return the date as a human-readable string.
- #to_time ⇒ Object
-
#upto(max, &block) ⇒ Object
Step forward one day at a time until we reach
max
(inclusive), yielding each date as we go. -
#wday ⇒ Object
Get the week day of this date.
-
#xmlschema ⇒ Object
:nodoc:.
-
#yday ⇒ Object
Get the day-of-the-year of this date.
-
#year ⇒ Object
Get the year of this date.
Methods included from Comparable
#<, #<=, #==, #>, #>=, #between?
Constructor Details
#initialize(ajd = 0, of = 0, sg = ITALY) ⇒ Date
NOTE this is the documentation for the method new!(). If you are reading this as the documentation for new(), that is because rdoc doesn’t fully support the aliasing of the initialize() method. new() is in fact an alias for #civil(): read the documentation for that method instead.
Create a new Date object.
ajd
is the Astronomical Julian Day Number. of
is the offset from UTC as a fraction of a day. Both default to 0.
sg
specifies the Day of Calendar Reform to use for this Date object.
Using one of the factory methods such as Date::civil is generally easier and safer.
1149 1150 1151 |
# File 'lib/framework/dateOrig.rb', line 1149 def initialize( time ) @m_date = time end |
Class Method Details
._httpdate(str) ⇒ Object
:nodoc:
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 |
# File 'lib/framework/date/format.rb', line 1199 def self._httpdate(str) # :nodoc: if /\A\s*(#{Date::Format::ABBR_DAYS.keys.join('|')})\s*,\s+ \d{2}\s+ (#{Date::Format::ABBR_MONTHS.keys.join('|')})\s+ -?\d{4}\s+ # allow minus, anyway \d{2}:\d{2}:\d{2}\s+ gmt\s*\z/iox =~ str _rfc2822(str) elsif /\A\s*(#{Date::Format::DAYS.keys.join('|')})\s*,\s+ \d{2}\s*-\s* (#{Date::Format::ABBR_MONTHS.keys.join('|')})\s*-\s* \d{2}\s+ \d{2}:\d{2}:\d{2}\s+ gmt\s*\z/iox =~ str _parse(str) elsif /\A\s*(#{Date::Format::ABBR_DAYS.keys.join('|')})\s+ (#{Date::Format::ABBR_MONTHS.keys.join('|')})\s+ \d{1,2}\s+ \d{2}:\d{2}:\d{2}\s+ \d{4}\s*\z/iox =~ str _parse(str) end end |
._iso8601(str) ⇒ Object
:nodoc:
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 |
# File 'lib/framework/date/format.rb', line 1100 def self._iso8601(str) # :nodoc: if /\A\s*(([-+]?\d{2,}|-)-\d{2}-\d{2}| ([-+]?\d{2,})?-\d{3}| (\d{2}|\d{4})?-w\d{2}-\d| -w-\d) (t \d{2}:\d{2}(:\d{2}([,.]\d+)?)? (z|[-+]\d{2}(:?\d{2})?)?)?\s*\z/ix =~ str _parse(str) elsif /\A\s*(([-+]?(\d{2}|\d{4})|--)\d{2}\d{2}| ([-+]?(\d{2}|\d{4}))?\d{3}|-\d{3}| (\d{2}|\d{4})?w\d{2}\d) (t? \d{2}\d{2}(\d{2}([,.]\d+)?)? (z|[-+]\d{2}(\d{2})?)?)?\s*\z/ix =~ str _parse(str) elsif /\A\s*(\d{2}:\d{2}(:\d{2}([,.]\d+)?)? (z|[-+]\d{2}(:?\d{2})?)?)?\s*\z/ix =~ str _parse(str) elsif /\A\s*(\d{2}\d{2}(\d{2}([,.]\d+)?)? (z|[-+]\d{2}(\d{2})?)?)?\s*\z/ix =~ str _parse(str) end end |
._jisx0301(str) ⇒ Object
:nodoc:
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 |
# File 'lib/framework/date/format.rb', line 1223 def self._jisx0301(str) # :nodoc: if /\A\s*[mtsh]?\d{2}\.\d{2}\.\d{2} (t (\d{2}:\d{2}(:\d{2}([,.]\d*)?)? (z|[-+]\d{2}(:?\d{2})?)?)?)?\s*\z/ix =~ str if /\A\s*\d/ =~ str _parse(str.sub(/\A\s*(\d)/, 'h\1')) else _parse(str) end else _iso8601(str) end end |
._parse(str, comp) ⇒ Object
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 |
# File 'lib/framework/date/format.rb', line 1034 def self._parse(str, comp=true) str = str.dup e = Date::Format::Bag.new e._comp = comp str.gsub!(/[^-+',.\/:@[:alnum:]\[\]]+/, ' ') _parse_time(str, e) # || _parse_beat(str, e) _parse_day(str, e) _parse_eu(str, e) || _parse_us(str, e) || _parse_iso(str, e) || _parse_jis(str, e) || _parse_vms(str, e) || _parse_sla(str, e) || _parse_dot(str, e) || _parse_iso2(str, e) || _parse_year(str, e) || _parse_mon(str, e) || _parse_mday(str, e) || _parse_ddd(str, e) if str.sub!(/\b(bc\b|bce\b|b\.c\.|b\.c\.e\.)/i, ' ') if e.year e.year = -e.year + 1 end end if str.sub!(/\A\s*(\d{1,2})\s*\z/, ' ') if e.hour && !e.mday v = $1.to_i if (1..31) === v e.mday = v end end if e.mday && !e.hour v = $1.to_i if (0..24) === v e.hour = v end end end if e._comp if e.cwyear if e.cwyear >= 0 && e.cwyear <= 99 e.cwyear += if e.cwyear >= 69 then 1900 else 2000 end end end if e.year if e.year >= 0 && e.year <= 99 e.year += if e.year >= 69 then 1900 else 2000 end end end end e.offset ||= zone_to_diff(e.zone) if e.zone e.to_hash end |
._rfc2822(str) ⇒ Object
:nodoc:
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 |
# File 'lib/framework/date/format.rb', line 1178 def self._rfc2822(str) # :nodoc: if /\A\s*(?:(?:#{Date::Format::ABBR_DAYS.keys.join('|')})\s*,\s+)? \d{1,2}\s+ (?:#{Date::Format::ABBR_MONTHS.keys.join('|')})\s+ -?(\d{2,})\s+ # allow minus, anyway \d{2}:\d{2}(:\d{2})?\s* (?:[-+]\d{4}|ut|gmt|e[sd]t|c[sd]t|m[sd]t|p[sd]t|[a-ik-z])\s*\z/iox =~ str e = _parse(str, false) if $1.size < 4 if e[:year] < 50 e[:year] += 2000 elsif e[:year] < 1000 e[:year] += 1900 end end e end end |
._rfc3339(str) ⇒ Object
:nodoc:
1125 1126 1127 1128 1129 1130 1131 1132 |
# File 'lib/framework/date/format.rb', line 1125 def self._rfc3339(str) # :nodoc: if /\A\s*-?\d{4}-\d{2}-\d{2} # allow minus, anyway (t|\s) \d{2}:\d{2}:\d{2}(\.\d+)? (z|[-+]\d{2}:\d{2})\s*\z/ix =~ str _parse(str) end end |
._rfc822(str) ⇒ Object
:nodoc:
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 |
# File 'lib/framework/date/format.rb', line 1197 def self._rfc2822(str) # :nodoc: if /\A\s*(?:(?:#{Date::Format::ABBR_DAYS.keys.join('|')})\s*,\s+)? \d{1,2}\s+ (?:#{Date::Format::ABBR_MONTHS.keys.join('|')})\s+ -?(\d{2,})\s+ # allow minus, anyway \d{2}:\d{2}(:\d{2})?\s* (?:[-+]\d{4}|ut|gmt|e[sd]t|c[sd]t|m[sd]t|p[sd]t|[a-ik-z])\s*\z/iox =~ str e = _parse(str, false) if $1.size < 4 if e[:year] < 50 e[:year] += 2000 elsif e[:year] < 1000 e[:year] += 1900 end end e end end |
._strptime(str, fmt) ⇒ Object
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/framework/date/format.rb', line 578 def self._strptime(str, fmt='%F') str = str.dup e = Date::Format::Bag.new return unless _strptime_i(str, fmt, e) if e._cent if e.cwyear e.cwyear += e._cent * 100 end if e.year e. year += e._cent * 100 end end if e._merid if e.hour e.hour %= 12 e.hour += e._merid end end unless str.empty? e.leftover = str end e.to_hash end |
._xmlschema(str) ⇒ Object
:nodoc:
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 |
# File 'lib/framework/date/format.rb', line 1134 def self._xmlschema(str) # :nodoc: if /\A\s*(-?\d{4,})(?:-(\d{2})(?:-(\d{2}))?)? (?:t (\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)? (z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str e = Date::Format::Bag.new e.year = $1.to_i e.mon = $2.to_i if $2 e.mday = $3.to_i if $3 e.hour = $4.to_i if $4 e.min = $5.to_i if $5 e.sec = $6.to_i if $6 e.sec_fraction = Rational($7.to_i, 10**$7.size) if $7 if $8 e.zone = $8 e.offset = zone_to_diff($8) end e.to_hash elsif /\A\s*(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))? (z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str e = Date::Format::Bag.new e.hour = $1.to_i if $1 e.min = $2.to_i if $2 e.sec = $3.to_i if $3 e.sec_fraction = Rational($4.to_i, 10**$4.size) if $4 if $5 e.zone = $5 e.offset = zone_to_diff($5) end e.to_hash elsif /\A\s*(?:--(\d{2})(?:-(\d{2}))?|---(\d{2})) (z|[-+]\d{2}:\d{2})?\s*\z/ix =~ str e = Date::Format::Bag.new e.mon = $1.to_i if $1 e.mday = $2.to_i if $2 e.mday = $3.to_i if $3 if $4 e.zone = $4 e.offset = zone_to_diff($4) end e.to_hash end end |
.civil(y = -4712,, m = 1, d = 1, sg = ITALY) ⇒ Object
Create a new Date object for the Civil Date specified by year y
, month m
, and day-of-month d
.
m
and d
can be negative, in which case they count backwards from the end of the year and the end of the month respectively. No wraparound is performed, however, and invalid values cause an ArgumentError to be raised. can be negative
y
defaults to -4712, m
to 1, and d
to 1; this is Julian Day Number day 0.
sg
specifies the Day of Calendar Reform.
130 131 132 |
# File 'lib/framework/dateME.rb', line 130 def self.civil(y=-4712, m=1, d=1, sg=2299161) Date.new( Time.new(y,m,d) ) end |
.commercial(y = -4712,, w = 1, d = 1, sg = ITALY) ⇒ Object
Create a new Date object for the Commercial Date specified by year y
, week-of-year w
, and day-of-week d
.
Monday is day-of-week 1; Sunday is day-of-week 7.
w
and d
can be negative, in which case they count backwards from the end of the year and the end of the week respectively. No wraparound is performed, however, and invalid values cause an ArgumentError to be raised.
y
defaults to -4712, w
to 1, and d
to 1; this is Julian Day Number day 0.
sg
specifies the Day of Calendar Reform.
839 840 841 842 843 844 |
# File 'lib/framework/dateOrig.rb', line 839 def self.commercial(y=-4712, w=1, d=1, sg=ITALY) unless jd = _valid_commercial?(y, w, d, sg) raise ArgumentError, 'invalid date' end new!(jd_to_ajd(jd, 0, 0), 0, sg) end |
.gregorian_leap?(y) ⇒ Boolean Also known as: leap?
Is a year a leap year in the Gregorian calendar?
All years divisible by 4 are leap years in the Gregorian calendar, except for years divisible by 100 and not by 400.
735 |
# File 'lib/framework/dateOrig.rb', line 735 def self.gregorian_leap? (y) y % 4 == 0 && y % 100 != 0 || y % 400 == 0 end |
.httpdate(str = 'Mon, 01 Jan -4712 00:00:00 GMT', sg = ITALY) ⇒ Object
:nodoc:
1100 1101 1102 1103 |
# File 'lib/framework/dateOrig.rb', line 1100 def self.httpdate(str='Mon, 01 Jan -4712 00:00:00 GMT', sg=ITALY) # :nodoc: elem = _httpdate(str) new_by_frags(elem, sg) end |
.iso8601(str = '-4712-01-01', sg = ITALY) ⇒ Object
:nodoc:
1078 1079 1080 1081 |
# File 'lib/framework/dateOrig.rb', line 1078 def self.iso8601(str='-4712-01-01', sg=ITALY) # :nodoc: elem = _iso8601(str) new_by_frags(elem, sg) end |
.jd(jd = 0, sg = ITALY) ⇒ Object
Create a new Date object from a Julian Day Number.
jd
is the Julian Day Number; if not specified, it defaults to 0. sg
specifies the Day of Calendar Reform.
781 782 783 784 |
# File 'lib/framework/dateOrig.rb', line 781 def self.jd(jd=0, sg=ITALY) jd = _valid_jd?(jd, sg) new!(jd_to_ajd(jd, 0, 0), 0, sg) end |
.jisx0301(str = '-4712-01-01', sg = ITALY) ⇒ Object
:nodoc:
1105 1106 1107 1108 |
# File 'lib/framework/dateOrig.rb', line 1105 def self.jisx0301(str='-4712-01-01', sg=ITALY) # :nodoc: elem = _jisx0301(str) new_by_frags(elem, sg) end |
.julian_leap?(y) ⇒ Boolean
Is a year a leap year in the Julian calendar?
All years divisible by 4 are leap years in the Julian calendar.
729 |
# File 'lib/framework/dateOrig.rb', line 729 def self.julian_leap? (y) y % 4 == 0 end |
.new ⇒ Object Also known as: new!
Create a new Date object for the Civil Date specified by year y
, month m
, and day-of-month d
.
m
and d
can be negative, in which case they count backwards from the end of the year and the end of the month respectively. No wraparound is performed, however, and invalid values cause an ArgumentError to be raised. can be negative
y
defaults to -4712, m
to 1, and d
to 1; this is Julian Day Number day 0.
sg
specifies the Day of Calendar Reform.
823 824 825 |
# File 'lib/framework/dateOrig.rb', line 823 def self.civil(y=-4712, m=1, d=1, sg=2299161) Date.new( Time.new(y,m,d) ) end |
.once(*ids) ⇒ Object
:nodoc: – restricted
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 |
# File 'lib/framework/dateOrig.rb', line 1112 def once(*ids) # :nodoc: -- restricted =begin for id in ids module_eval <<-"end;" alias_method :__#{id.object_id}__, :#{id.to_s} private :__#{id.object_id}__ def #{id.to_s}(*args) @__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args) end end; end =end end |
.ordinal(y = -4712,, d = 1, sg = ITALY) ⇒ Object
Create a new Date object from an Ordinal Date, specified by year y
and day-of-year d
. d
can be negative, in which it counts backwards from the end of the year. No year wraparound is performed, however. An invalid value for d
results in an ArgumentError being raised.
y
defaults to -4712, and d
to 1; this is Julian Day Number day 0.
sg
specifies the Day of Calendar Reform.
796 797 798 799 800 801 |
# File 'lib/framework/dateOrig.rb', line 796 def self.ordinal(y=-4712, d=1, sg=ITALY) unless jd = _valid_ordinal?(y, d, sg) raise ArgumentError, 'invalid date' end new!(jd_to_ajd(jd, 0, 0), 0, sg) end |
.parse(str = '-4712-01-01', comp = true, sg = ITALY) ⇒ Object
Create a new Date object by parsing from a String, without specifying the format.
str
is a String holding a date representation. comp
specifies whether to interpret 2-digit years as 19XX (>= 69) or 20XX (< 69); the default is not to. The method will attempt to parse a date from the String using various heuristics; see #_parse in date/format.rb for more details. If parsing fails, an ArgumentError will be raised.
The default str
is ‘-4712-01-01’; this is Julian Day Number day 0.
sg
specifies the Day of Calendar Reform.
1073 1074 1075 1076 |
# File 'lib/framework/dateOrig.rb', line 1073 def self.parse(str='-4712-01-01', comp=true, sg=ITALY) elem = _parse(str, comp) new_by_frags(elem, sg) end |
.rfc2822(str = 'Mon, 1 Jan -4712 00:00:00 +0000', sg = ITALY) ⇒ Object
:nodoc:
1093 1094 1095 1096 |
# File 'lib/framework/dateOrig.rb', line 1093 def self.rfc2822(str='Mon, 1 Jan -4712 00:00:00 +0000', sg=ITALY) # :nodoc: elem = _rfc2822(str) new_by_frags(elem, sg) end |
.rfc3339(str = '-4712-01-01T00:00:00+00:00', sg = ITALY) ⇒ Object
:nodoc:
1083 1084 1085 1086 |
# File 'lib/framework/dateOrig.rb', line 1083 def self.rfc3339(str='-4712-01-01T00:00:00+00:00', sg=ITALY) # :nodoc: elem = _rfc3339(str) new_by_frags(elem, sg) end |
.rfc822 ⇒ Object
:nodoc:
1098 1099 1100 1101 |
# File 'lib/framework/dateOrig.rb', line 1098 def self.rfc2822(str='Mon, 1 Jan -4712 00:00:00 +0000', sg=ITALY) # :nodoc: elem = _rfc2822(str) new_by_frags(elem, sg) end |
.strptime(str = '-4712-01-01', fmt = '%F', sg = ITALY) ⇒ Object
Create a new Date object by parsing from a String according to a specified format.
str
is a String holding a date representation. fmt
is the format that the date is in. See date/format.rb for details on supported formats.
The default str
is ‘-4712-01-01’, and the default fmt
is ‘%F’, which means Year-Month-Day_of_Month. This gives Julian Day Number day 0.
sg
specifies the Day of Calendar Reform.
An ArgumentError will be raised if str
cannot be parsed.
1053 1054 1055 |
# File 'lib/framework/dateOrig.rb', line 1053 def self.strptime(str='-4712-01-01', fmt='%F') Date.new( Time.strptime(str,fmt) ) end |
.today(sg = ITALY) ⇒ Object
Create a new Date object representing today.
sg
specifies the Day of Calendar Reform.
1824 1825 1826 |
# File 'lib/framework/dateOrig.rb', line 1824 def self.today Date.new( Time.now ) end |
.valid_civil?(y, m, d, sg = ITALY) ⇒ Boolean Also known as: valid_date?
748 749 750 |
# File 'lib/framework/dateOrig.rb', line 748 def self.valid_civil? (y, m, d, sg=ITALY) !!_valid_civil?(y, m, d, sg) end |
.valid_commercial?(y, w, d, sg = ITALY) ⇒ Boolean
754 755 756 |
# File 'lib/framework/dateOrig.rb', line 754 def self.valid_commercial? (y, w, d, sg=ITALY) !!_valid_commercial?(y, w, d, sg) end |
.valid_jd?(jd, sg = ITALY) ⇒ Boolean
740 741 742 |
# File 'lib/framework/dateOrig.rb', line 740 def self.valid_jd? (jd, sg=ITALY) !!_valid_jd?(jd, sg) end |
.valid_ordinal?(y, d, sg = ITALY) ⇒ Boolean
744 745 746 |
# File 'lib/framework/dateOrig.rb', line 744 def self.valid_ordinal? (y, d, sg=ITALY) !!_valid_ordinal?(y, d, sg) end |
.xmlschema(str = '-4712-01-01', sg = ITALY) ⇒ Object
:nodoc:
1088 1089 1090 1091 |
# File 'lib/framework/dateOrig.rb', line 1088 def self.xmlschema(str='-4712-01-01', sg=ITALY) # :nodoc: elem = _xmlschema(str) new_by_frags(elem, sg) end |
Instance Method Details
#+(n) ⇒ Object
Return a new Date object that is n
days later than the current one.
n
may be a negative value, in which case the new Date is earlier than the current one; however, #-() might be more intuitive.
If n
is not a Numeric, a TypeError will be thrown. In particular, two Dates cannot be added to each other.
1347 1348 1349 1350 1351 1352 1353 |
# File 'lib/framework/dateOrig.rb', line 1347 def + (x) case x when Numeric; return Date.new( @m_date + x*(60*60*24) ) end raise TypeError, 'expected numeric' end |
#-(x) ⇒ Object
If x
is a Numeric value, create a new Date object that is x
days earlier than the current one.
If x
is a Date, return the number of days between the two dates; or, more precisely, how many days later the current date is than x
.
If x
is neither Numeric nor a Date, a TypeError is raised.
1362 1363 1364 1365 1366 1367 1368 1369 |
# File 'lib/framework/dateOrig.rb', line 1362 def - (x) case x when Numeric; return Date.new( @m_date - x*(60*60*24) ) when Date; return ((@m_date-x._get_date()).to_i)/(60*60*24) end raise TypeError, 'expected numeric or date' end |
#<<(n) ⇒ Object
Return a new Date object that is n
months earlier than the current one.
If the day-of-the-month of the current Date is greater than the last day of the target month, the day-of-the-month of the returned Date will be the last day of the target month.
1446 |
# File 'lib/framework/dateOrig.rb', line 1446 def << (n) self >> -n end |
#<=>(other) ⇒ Object
Compare this date with another date.
other
can also be a Numeric value, in which case it is interpreted as an Astronomical Julian Day Number.
Comparison is by Astronomical Julian Day Number, including fractional days. This means that both the time and the timezone offset are taken into account when comparing two DateTime instances. When comparing a DateTime instance with a Date instance, the time of the latter will be considered as falling on midnight UTC.
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 |
# File 'lib/framework/dateOrig.rb', line 1381 def <=> (other) case other when Numeric; return @ajd <=> other when Date; return @ajd <=> other.ajd else begin l, r = other.coerce(self) return l <=> r rescue NoMethodError end end nil end |
#===(other) ⇒ Object
The relationship operator for Date.
Compares dates by Julian Day Number. When comparing two DateTime instances, or a DateTime with a Date, the instances will be regarded as equivalent if they fall on the same date in local time.
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 |
# File 'lib/framework/dateOrig.rb', line 1401 def === (other) case other when Numeric; return jd == other when Date; return jd == other.jd else begin l, r = other.coerce(self) return l === r rescue NoMethodError end end false end |
#>>(n) ⇒ Object
Return a new Date object that is n
months later than the current one.
If the day-of-the-month of the current Date is greater than the last day of the target month, the day-of-the-month of the returned Date will be the last day of the target month.
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 |
# File 'lib/framework/dateOrig.rb', line 1429 def >> (n) y, m = (year * 12 + (mon - 1) + n).divmod(12) m, = (m + 1) .divmod(1) d = mday until jd2 = _valid_civil?(y, m, d, @sg) d -= 1 raise ArgumentError, 'invalid date' unless d > 0 end self + (jd2 - jd) end |
#_get_date ⇒ Object
134 135 136 |
# File 'lib/framework/dateME.rb', line 134 def _get_date @m_date end |
#ajd ⇒ Object
Get the date as an Astronomical Julian Day Number.
1155 |
# File 'lib/framework/dateOrig.rb', line 1155 def ajd() @ajd end |
#amjd ⇒ Object
Get the date as an Astronomical Modified Julian Day Number.
1158 |
# File 'lib/framework/dateOrig.rb', line 1158 def amjd() ajd_to_amjd(@ajd) end |
#asctime ⇒ Object
alias_method :format, :strftime
344 |
# File 'lib/framework/date/format.rb', line 344 def asctime() strftime('%c') end |
#ctime ⇒ Object
alias_method :format, :strftime
346 |
# File 'lib/framework/date/format.rb', line 346 def asctime() strftime('%c') end |
#cwday ⇒ Object
Get the commercial day of the week of this date. Monday is commercial day-of-week 1; Sunday is commercial day-of-week 7.
161 162 163 164 165 166 |
# File 'lib/framework/dateME.rb', line 161 def cwday() _wday = @m_date.wday return 7 if _wday == 0 return _wday end |
#cweek ⇒ Object
Get the commercial week of the year of this date.
1251 |
# File 'lib/framework/dateOrig.rb', line 1251 def cweek() commercial[1] end |
#cwyear ⇒ Object
Get the commercial year of this date. See Commercial Date in the introduction for how this differs from the normal year.
1248 |
# File 'lib/framework/dateOrig.rb', line 1248 def cwyear() commercial[0] end |
#day_fraction ⇒ Object
Get any fractional day part of the date.
1166 |
# File 'lib/framework/dateOrig.rb', line 1166 def day_fraction() ajd_to_jd(@ajd, @of)[1] end |
#downto(min, &block) ⇒ Object
Step backward one day at a time until we reach min
(inclusive), yielding each date as we go.
1486 1487 1488 |
# File 'lib/framework/dateOrig.rb', line 1486 def downto(min, &block) # :yield: date step(min, -1, &block) end |
#england ⇒ Object
Create a copy of this Date object that uses the English/Colonial Day of Calendar Reform.
1317 |
# File 'lib/framework/dateOrig.rb', line 1317 def england() new_start(self.class::ENGLAND) end |
#eql?(other) ⇒ Boolean
Is this Date equal to other
?
other
must both be a Date object, and represent the same date.
1493 |
# File 'lib/framework/dateOrig.rb', line 1493 def eql? (other) Date === other && self == other end |
#gregorian ⇒ Object
Create a copy of this Date object that always uses the Gregorian Calendar.
1325 |
# File 'lib/framework/dateOrig.rb', line 1325 def gregorian() new_start(self.class::GREGORIAN) end |
#gregorian? ⇒ Boolean
Is the current date new-style (Gregorian Calendar)?
1285 |
# File 'lib/framework/dateOrig.rb', line 1285 def gregorian? () !julian? end |
#hash ⇒ Object
Calculate a hash value for this date.
1496 |
# File 'lib/framework/dateOrig.rb', line 1496 def hash() @ajd.hash end |
#httpdate ⇒ Object
:nodoc:
358 |
# File 'lib/framework/date/format.rb', line 358 def httpdate() new_offset(0).strftime('%a, %d %b %Y %T GMT') end |
#inspect ⇒ Object
Return internal object state as a programmer-readable string.
1499 1500 1501 |
# File 'lib/framework/dateOrig.rb', line 1499 def inspect format('#<%s: %s (%s,%s,%s)>', self.class, to_s, @ajd, @of, @sg) end |
#iso8601 ⇒ Object
348 |
# File 'lib/framework/date/format.rb', line 348 def iso8601() strftime('%F') end |
#italy ⇒ Object
Create a copy of this Date object that uses the Italian/Catholic Day of Calendar Reform.
1313 |
# File 'lib/framework/dateOrig.rb', line 1313 def italy() new_start(self.class::ITALY) end |
#jd ⇒ Object
Get the date as a Julian Day Number.
1163 |
# File 'lib/framework/dateOrig.rb', line 1163 def jd() ajd_to_jd(@ajd, @of)[0] end |
#jisx0301 ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/framework/date/format.rb', line 360 def jisx0301 if jd < 2405160 iso8601 else case jd when 2405160...2419614 g = 'M%02d' % (year - 1867) when 2419614...2424875 g = 'T%02d' % (year - 1911) when 2424875...2447535 g = 'S%02d' % (year - 1925) else g = 'H%02d' % (year - 1988) end g + strftime('.%m.%d') end end |
#julian ⇒ Object
Create a copy of this Date object that always uses the Julian Calendar.
1321 |
# File 'lib/framework/dateOrig.rb', line 1321 def julian() new_start(self.class::JULIAN) end |
#julian? ⇒ Boolean
Is the current date old-style (Julian Calendar)?
1282 |
# File 'lib/framework/dateOrig.rb', line 1282 def julian? () jd < @sg end |
#ld ⇒ Object
Get the date as the number of days since the Day of Calendar Reform (in Italy and the Catholic countries).
1173 |
# File 'lib/framework/dateOrig.rb', line 1173 def ld() jd_to_ld(jd) end |
#leap? ⇒ Boolean
Is this a leap year?
1298 1299 1300 1301 |
# File 'lib/framework/dateOrig.rb', line 1298 def leap? jd_to_civil(civil_to_jd(year, 3, 1, fix_style) - 1, fix_style)[-1] == 29 end |
#marshal_dump ⇒ Object
Dump to Marshal format.
1509 |
# File 'lib/framework/dateOrig.rb', line 1509 def marshal_dump() [@ajd, @of, @sg] end |
#marshal_load(a) ⇒ Object
Load from Marshal format.
1512 1513 1514 1515 |
# File 'lib/framework/dateOrig.rb', line 1512 def marshal_load(a) @ajd, @of, @sg, = a @__ca__ = {} end |
#mday ⇒ Object Also known as: day
Get the day-of-the-month of this date.
1206 |
# File 'lib/framework/dateOrig.rb', line 1206 def mday() @m_date.mday end |
#mjd ⇒ Object
Get the date as a Modified Julian Day Number.
1169 |
# File 'lib/framework/dateOrig.rb', line 1169 def mjd() jd_to_mjd(jd) end |
#mon ⇒ Object Also known as: month
Get the month of this date.
January is month 1.
172 |
# File 'lib/framework/dateME.rb', line 172 def mon() @m_date.mon end |
#new_start(sg = self.class::ITALY) ⇒ Object
Create a copy of this Date object using a new Day of Calendar Reform.
1309 |
# File 'lib/framework/dateOrig.rb', line 1309 def new_start(sg=self.class::ITALY) self.class.new!(@ajd, @of, sg) end |
#next ⇒ Object Also known as: succ
Return a new Date one day after this one.
1419 |
# File 'lib/framework/dateOrig.rb', line 1419 def next() next_day end |
#next_day(n = 1) ⇒ Object
1415 |
# File 'lib/framework/dateOrig.rb', line 1415 def next_day(n=1) self + n end |
#next_month(n = 1) ⇒ Object
1448 |
# File 'lib/framework/dateOrig.rb', line 1448 def next_month(n=1) self >> n end |
#next_year(n = 1) ⇒ Object
1451 |
# File 'lib/framework/dateOrig.rb', line 1451 def next_year(n=1) self >> n * 12 end |
#old_strftime ⇒ Object
11 |
# File 'lib/framework/date.rb', line 11 alias_method :old_strftime, :strftime |
#prev_day(n = 1) ⇒ Object
1416 |
# File 'lib/framework/dateOrig.rb', line 1416 def prev_day(n=1) self - n end |
#prev_month(n = 1) ⇒ Object
1449 |
# File 'lib/framework/dateOrig.rb', line 1449 def prev_month(n=1) self << n end |
#prev_year(n = 1) ⇒ Object
1452 |
# File 'lib/framework/dateOrig.rb', line 1452 def prev_year(n=1) self << n * 12 end |
#rfc2822 ⇒ Object
354 |
# File 'lib/framework/date/format.rb', line 354 def rfc2822() strftime('%a, %-d %b %Y %T %z') end |
#rfc3339 ⇒ Object
350 |
# File 'lib/framework/date/format.rb', line 350 def rfc3339() iso8601 end |
#rfc822 ⇒ Object
356 |
# File 'lib/framework/date/format.rb', line 356 def rfc2822() strftime('%a, %-d %b %Y %T %z') end |
#start ⇒ Object
When is the Day of Calendar Reform for this Date object?
1306 |
# File 'lib/framework/dateOrig.rb', line 1306 def start() @sg end |
#step(limit, step = 1) ⇒ Object
Step the current date forward step
days at a time (or backward, if step
is negative) until we reach limit
(inclusive), yielding the resultant date at each step.
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 |
# File 'lib/framework/dateOrig.rb', line 1460 def step(limit, step=1) # :yield: date =begin if step.zero? raise ArgumentError, "step can't be 0" end =end unless block_given? return to_enum(:step, limit, step) end da = self op = %w(- <= >=)[step <=> 0] while da.__send__(op, limit) yield da da += step end self end |
#strftime(fmt) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/framework/date.rb', line 23 def strftime(date) if LocalizationSimplified::get_cur_locale() == 'en' return old_strftime(date) end tmpdate=date.dup LocalizationSimplified::localize_strftime(tmpdate, self) old_strftime(tmpdate) end |
#to_date ⇒ Object
194 |
# File 'lib/framework/dateME.rb', line 194 def to_date() self end |
#to_datetime ⇒ Object
1819 |
# File 'lib/framework/dateOrig.rb', line 1819 def to_datetime() DateTime.new!(jd_to_ajd(jd, 0, 0), @of, @sg) end |
#to_formatted_s(type) ⇒ Object
34 35 36 |
# File 'lib/framework/date.rb', line 34 def to_formatted_s(type) strftime(DATE_FORMATS[type]) end |
#to_s ⇒ Object
Return the date as a human-readable string.
The format used is YYYY-MM-DD.
1506 1507 1508 |
# File 'lib/framework/dateOrig.rb', line 1506 def to_s() format('%.4d-%02d-%02d', year(), mon(), mday()) end |
#to_time ⇒ Object
193 |
# File 'lib/framework/dateME.rb', line 193 def to_time() Time.local(year(), mon(), mday()) end |
#upto(max, &block) ⇒ Object
Step forward one day at a time until we reach max
(inclusive), yielding each date as we go.
1480 1481 1482 |
# File 'lib/framework/dateOrig.rb', line 1480 def upto(max, &block) # :yield: date step(max, +1, &block) end |
#wday ⇒ Object
Get the week day of this date. Sunday is day-of-week 0; Saturday is day-of-week 6.
157 |
# File 'lib/framework/dateME.rb', line 157 def wday() @m_date.wday end |
#xmlschema ⇒ Object
:nodoc:
352 |
# File 'lib/framework/date/format.rb', line 352 def xmlschema() iso8601 end |
#yday ⇒ Object
Get the day-of-the-year of this date.
January 1 is day-of-the-year 1
1198 |
# File 'lib/framework/dateOrig.rb', line 1198 def yday() ordinal[1] end |
#year ⇒ Object
Get the year of this date.
1193 |
# File 'lib/framework/dateOrig.rb', line 1193 def year() @m_date.year end |