日期对象中包含的额外数据是什么?给定以下示例:
time = Time.at(1392328830)
# => 2014-02-13 15:00:30 -0700
date = time.to_date
# => #<Date: 2014-02-13 ((2456702j,0s,0n),+0s,2299161j)>
这一切代表什么?从 Ruby Date documentation 看不清楚。
((2456702j,0s,0n),+0s,2299161j)
最佳答案
您看到的是 Object.inspect
的输出,即 a human-readable representation of an object .对于 Date
类:
来自date.rb:
# Return internal object state as a programmer-readable string.
def inspect() format('#<%s: %s,%s,%s>', self.class, @ajd, @of, @sg) end
# Return the date as a human-readable string.
#
# The format used is YYYY-MM-DD.
def to_s() strftime end
实例变量是:
@ajd
是一个天文儒略日数@of
是与 UTC 的偏移量或一天的一小部分@sg
是日历改革日
但是这些术语是什么意思?
1。什么是天文儒略日数? (@ajd)
For scientific purposes, it is convenient to refer to a date simply as a day count, counting from an arbitrary initial day. The date first chosen for this was January 1, 4713 BCE. A count of days from this date is the Julian *Day* Number or Julian *Date*. This is in local time, and counts from midnight on the initial day. The stricter usage is in UTC, and counts from midday on the initial day. This is referred to in the Date class as the Astronomical *Julian* Day *Number*. In the Date class, the Astronomical Julian Day Number includes fractional days.
2。从什么偏移? (@offset)
Time zones are represented as an offset from UTC, as a fraction of a day. This offset is the how much local time is later (or earlier) than UTC. UTC offset 0 is centered on England (also known as GMT). As you travel east, the offset increases until you reach the dateline in the middle of the Pacific Ocean; as you travel west, the offset decreases.
3。什么是历法改革日? (@sg)
The Gregorian Calendar was introduced at different times in different regions. The day on which it was introduced for a particular region is the Day *of* Calendar *Reform* for that region. This is abbreviated as
sg
(for Start of Gregorian calendar) in the Date class.
据我所知,公历是通过闰年 self 更正的日历。
关于ruby - 检查 Date 对象时的额外数据是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21791054/