tag:blogger.com,1999:blog-9905395.post8083874223488930079..comments2023-06-13T02:09:57.338-06:00Comments on David Rupp's Blog: Ruby's inject(): Putting the 'Fun' in 'Functional Programming' Since ... Oh, About 4:15 This MorningDavid Rupphttp://www.blogger.com/profile/16410820024654313029noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-9905395.post-6145239718582332112009-10-19T15:17:52.643-06:002009-10-19T15:17:52.643-06:00If you need to handle years you also need to compe...If you need to handle years you also need to compensate for Time.at(0) not starting at year 0 but at 1970. Come to think of it I think I prefer your solution because it's general and needs no tweaking. There really should be a timespan somewhere in the Ruby core but I can't find it.<br />I don't know if you want to bring in the ActiveSupport beast but if you do the http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Numeric/Time.html might save your day.Jonas Elfströmhttps://www.blogger.com/profile/18088865137364783994noreply@blogger.comtag:blogger.com,1999:blog-9905395.post-68739884603380112792009-10-19T10:37:51.833-06:002009-10-19T10:37:51.833-06:00@Jonas: I was hoping at first that I could use Tim...@Jonas: I was hoping at first that I could use Time.at(), but some things about it bothered me. For example, when I run Time.at(356521 - 3600*25) locally (Atlanta, GA, US) I get Sat Jan 03 21:02:01 -0500 1970. Plus, I had to figure out why used 25 and not 24 (apparently you're in UTC + 1). <br /><br />We can use your trick plus a quick call to utc() to correct for local timezones and the fact that the beginning of the epoch is Day 1 (not Day 0) thusly -- Time.at(356521 - 3600*24).utc.<br /><br />Thanks for the tip. :-)David Rupphttps://www.blogger.com/profile/16410820024654313029noreply@blogger.comtag:blogger.com,1999:blog-9905395.post-73225221101911595252009-10-19T07:35:54.379-06:002009-10-19T07:35:54.379-06:00How about
>> t=Time.at(356521-3600*25)
=>...How about<br /><br />>> t=Time.at(356521-3600*25)<br />=> Sun Jan 04 03:02:01 0100 1970<br />>> t.day<br />=> 4<br />>> t.hour<br />=> 3<br />>> t.min<br />=> 2<br />>> t.sec<br />=> 1Jonas Elfströmhttps://www.blogger.com/profile/18088865137364783994noreply@blogger.comtag:blogger.com,1999:blog-9905395.post-59842242664466490402009-10-14T11:28:43.570-06:002009-10-14T11:28:43.570-06:00Hi David,
I came up with something similar that d...Hi David,<br /><br />I came up with something similar that doesn't have any side effects, and thought that you may find it useful.<br /><br /><a href="http://billsix.blogspot.com/2009/10/scanl.html" rel="nofollow"> ScanL </a><br /><br />Regards,<br />BillBill Sixhttps://www.blogger.com/profile/17140165698141704596noreply@blogger.com