如何使用ruby日期常量GREGORIAN,JULIAN,ENGLAND甚至意大利 [英] How do I use ruby Date constants GREGORIAN, JULIAN, ENGLAND and even ITALY

查看:320
本文介绍了如何使用ruby日期常量GREGORIAN,JULIAN,ENGLAND甚至意大利的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在学习红宝石的日期助手。

  1.9.3p125:057> Date :: ABBR_MONTHNAMES 
=> [无]月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月, ]
1.9.3p125:058> Date :: ABBR_DAYNAMES
=> [太阳,星期一,星期二,星期三,星期四,星期五,星期六]
1.9.3p125:059>日期:: MONTHNAMES
=> 十月,十一月,十二月,十一月,十二月,十一月,十二月 ]
1.9.3p125:060> Date :: DAYNAMES
=> [星期日,星期一,星期二,星期三,星期四,星期五,星期六]
1.9.3p125:070>日期:: MONTHNAMES [Time.new.month]
=> 八月

有趣的东西!但是,GREGORIAN,JULIAN,ENGLAND和ITALY(!)常量呢?他们是什么/如何使用它们?
我可以输出:

  1.9.3p125:061>日期:: GREGORIAN 
=> -Infinity
1.9.3p125:062> Date :: JULIAN
=>无限
1.9.3p125:063> Date :: ENGLAND
=> 2361222

 code> 1.9.3p125:067> Date.new 
=> #<日期:-4712-01-01((0j,0s,0n),+ 0s,2299161j)>
1.9.3p125:068> Date.new.new_start(Date :: JULIAN)
=> #<日期:-4712-01-01((0j,0s,0n),+ 0s,Infj)>
1.9.3p125:069> Date.new.new_start(Date :: ENGLAND)
=> #< Date:-4712-01-01((0j,0s,0n),+ 0s,2361222j)>

从以下看起来,Julian是几天之后的日历。我记得几个世纪以前学习有关日历的重置,所以这是有道理的,但是英国和意大利人以及如何使用它们仍然不清楚。

  1.9.3p125:076> Date.new(1977,7,1).new_start(Date :: ENGLAND)
=> #< Date:1977-07-01((2443326j,0s,0n),+ 0s,2361222j)>
1.9.3p125:077> Date.new(1977,7,1).new_start(Date :: ITALY)
=> #< Date:1977-07-01((2443326j,0s,0n),+ 0s,2299161j)>
1.9.3p125:078> Date.new(1977,7,1).new_start(Date :: JULIAN)
=> #< Date:1977-06-18((2443326j,0s,0n),+ 0s,Infj)>


解决方案

所有的常数都在文档。根据经验,如果下面的解释对你来说并不意味着什么,你可能根本不需要担心这些常数。


英国
日历改革日的朱利安日数英格兰及其殖民地。



GREGORIAN日历日的朱利安日数
proleptic Gregorian calendar的改革



意大利意大利日历改革日的儒略日数
和一些天主教国家。



JULIAN
proleptic朱利安日历日历改革日的朱利安日数


以下是不同日历系统上的更多信息:




'scuse the upper case, they are constants.

I am having fun learning ruby's Date helpers.

1.9.3p125 :057 > Date::ABBR_MONTHNAMES
 => [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] 
1.9.3p125 :058 > Date::ABBR_DAYNAMES
 => ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] 
1.9.3p125 :059 > Date::MONTHNAMES
 => [nil, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] 
1.9.3p125 :060 > Date::DAYNAMES
 => ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] 
1.9.3p125 :070 > Date::MONTHNAMES[Time.new.month]
=> "August" 

Fun stuff! But what about the GREGORIAN, JULIAN, ENGLAND and ITALY (!) constants. What are they for / how do I use them? I can output:

1.9.3p125 :061 > Date::GREGORIAN
 => -Infinity 
1.9.3p125 :062 > Date::JULIAN
 => Infinity 
1.9.3p125 :063 > Date::ENGLAND
 => 2361222 

or

1.9.3p125 :067 > Date.new
 => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2299161j)> 
1.9.3p125 :068 > Date.new.new_start(Date::JULIAN)
 => #<Date: -4712-01-01 ((0j,0s,0n),+0s,Infj)> 
1.9.3p125 :069 > Date.new.new_start(Date::ENGLAND)
 => #<Date: -4712-01-01 ((0j,0s,0n),+0s,2361222j)> 

From the following it looks like Julian is a calendar that is off by a few days. I remember learning about the calendar reset for that a few centuries ago so that makes sense, however the ENGLAND and ITALY and how they would be used is still unclear to me.

1.9.3p125 :076 > Date.new(1977,7,1).new_start(Date::ENGLAND)
 => #<Date: 1977-07-01 ((2443326j,0s,0n),+0s,2361222j)> 
1.9.3p125 :077 > Date.new(1977,7,1).new_start(Date::ITALY)
 => #<Date: 1977-07-01 ((2443326j,0s,0n),+0s,2299161j)> 
1.9.3p125 :078 > Date.new(1977,7,1).new_start(Date::JULIAN)
 => #<Date: 1977-06-18 ((2443326j,0s,0n),+0s,Infj)> 

解决方案

All the constants are explained in the documentation. As a rule of thumb, if the below explanations don't mean anything to you, you probably don't need to worry about those constants at all.

ENGLAND The Julian day number of the day of calendar reform for England and her colonies.

GREGORIAN The Julian day number of the day of calendar reform for the proleptic Gregorian calendar

ITALY The Julian day number of the day of calendar reform for Italy and some catholic countries.

JULIAN The Julian day number of the day of calendar reform for the proleptic Julian calendar

Here's more info on the different calendar systems:

这篇关于如何使用ruby日期常量GREGORIAN,JULIAN,ENGLAND甚至意大利的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆