• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Expressiveness using implicit conversions

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fiddled with your code before going to bed. This was a ton of fun!

Maybe what I did will spark some more ideas:

2 am: Sun Jul 13 02:00:00 EDT 2008
3 pm yesterday: Sat Jul 12 15:00:00 EDT 2008
noon tomorrow: Mon Jul 14 12:00:00 EDT 2008
12:05 - Sun Jul 13 12:05:00 EDT 2008

I was surprised that the Calendar treats noon as 12 am and midnight as 12 pm.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty slick, Garrett, and Marc. Thanks for showing that. And Garrett - greetings from a former Arizonan.

[Marc]: I was surprised that the Calendar treats noon as 12 am and midnight as 12 pm.

What makes you say that? The documentation for Calendar says otherwise:

"Although historically not precise, midnight also belongs to "am", and noon belongs to "pm", so on the same day, 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic