ruby - 检查 Date 对象时的额外数据是什么?

标签 ruby date ruby-2.0

日期对象中包含的额外数据是什么?给定以下示例:

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

实例变量是:

  1. @ajd 是一个天文儒略日数
  2. @of 是与 UTC 的偏移量或一天的一小部分
  3. @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/

相关文章:

ruby - 如何设置 Sequel 模型中的默认值?

ruby - 使用 Ruby 计算一年中的周数

python - 我有一个 Pandas 数据框,每周有几周和几天。如何考虑日期与日期匹配的行?

gem - 在 Windows 8 上使用 gem 安装 SASS

ruby - 在不捕获 STDOUT 或 STDERR 的情况下访问子进程的 STDIN

ruby - Bundler 现在是否从 FaSTLy CDN 获取 gem ?

ruby-on-rails - Rails 3.1 限制用户创建的对象

sql - rails/SQL : finding invoices by checking two sums

php - 如何确定 UTC 与服务器时区的偏移量?

ruby - rake 错误 : "warning: already initialized constant FileUtils::OPT_TABLE"