I checked out Ruby at the weekend and was having a go at some tutorials.
There was an 'numbers excercise' part...
how many seconds old are you?
how many minutes are in a decade?
...which I had a go at in REBOL because I wanted to account for leap years. I thought the NOW function would be really handy for this type of job so I coded 'how many seconds old are you?'.
REBOL[]
days_old: now - 23-Nov-1975
seconds_old: days_old * 86400
print ["You are" seconds_old "seconds old on this DAY."]
nt: now/time
hour: nt/hour
mins: nt/minute
sec: nt/second
get_seconds: (hour * 3600) + (mins * 60) + sec
exactly: seconds_old + get_seconds
print ["You were" exactly "seconds old when this program was executed!"]
halt
Which worked ok (I think).
But then I tried 'how many minutes are in a decade?' and got stuck.
I was going to work it like...
todays date minus todays date 10 years ago
...which gets my decade with any leap year irregularities thrown in.
I had a lot of problems with this. I could subtract 10 years from now/year, but then couldn't get it back on a whole date value.
I suppose I was then going to get the days between them and convert days-to-minutes.
Any ideas?