Ruby Interesting: "Dates are complicated"

zhangkaizhao · 2021年09月28日 · 193 次阅读

https://ruby-doc.org/stdlib-3.0.2/libdoc/date/rdoc/Date.html#method-c-today

The optional arg for Date.today(start=Date::ITALY) specifies a calendar start date to use for calculation of today's date.

[43] pry(main)> Date.today()                                            
=> #<Date: 2021-09-27 ((2459485j,0s,0n),+0s,2299161j)>
[44] pry(main)> Date.today(Date::ITALY)                                 
=> #<Date: 2021-09-27 ((2459485j,0s,0n),+0s,2299161j)>
[45] pry(main)> Date.today(Date::JULIAN)                                
=> #<Date: 2021-09-14 ((2459485j,0s,0n),+0s,Infj)>

# these are the same

[48] pry(main)> Date.today +1                                           
=> #<Date: 2021-09-27 ((2459485j,0s,0n),+0s,2299161j)>
[49] pry(main)> Date.today(1)                                           
=> #<Date: 2021-09-27 ((2459485j,0s,0n),+0s,2299161j)>

# these are the same

[51] pry(main)> Date.today + 1                                          
=> #<Date: 2021-09-28 ((2459486j,0s,0n),+0s,2299161j)>
[52] pry(main)> Date.today() + 1                                        
=> #<Date: 2021-09-28 ((2459486j,0s,0n),+0s,2299161j)>

TIL: Dates are complicated, and even good tools have sharp edges.

-gf-

via Ruby users <[email protected]> 邮件组之话题“simple operations”

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号