This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I was considering this post about the expressiveness of the Ruby Date/Time functions, and was wondering if the same type of syntax could be duplicated in Scala. After about 20 minutes hacking around, here's what I came up with. I'm not sure I'm completely in love with the abstraction, but the method calls look the same.
Output: 2 weeks from now: Sat Jul 26 14:58:44 MST 2008 10 days from now: Tue Jul 22 14:58:44 MST 2008 5 minutes ago: Sat Jul 12 14:53:44 MST 2008 [ July 12, 2008: Message edited by: Garrett Rowe ]
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
I was surprised that the Calendar treats noon as 12 am and midnight as 12 pm.
A good workman is known by his tools.
Joined: Jan 17, 2006
I'll see your extensions and raise you some more sugary sweet syntax.
1 day ago: Sat Jul 12 02:16:38 MST 2008 Yesterday at 3:00: Sat Jul 12 03:00:00 MST 2008 30 days from now at midnight: Tue Aug 12 00:00:00 MST 2008 Tomorrow at 3 AM: Mon Jul 14 03:00:00 MST 2008 30 days from 8 hours from now: Tue Aug 12 10:16:38 MST 2008 30 days + 8 hours from now: Tue Aug 12 10:16:38 MST 2008 [ July 13, 2008: Message edited by: Garrett Rowe ]