Date Math
Fairlight
fairlite at fairlite.com
Tue May 16 08:39:22 PDT 2006
At Tue, May 16, 2006 at 02:13:51PM +0000 or thereabouts,
suspect William B. Eppler, Jr. was observed uttering:
>
> I need to go over several days. Not an easy feat as I am finding!!
Here's my thinking on doing it:
Compare dates.
A) Identical date - straight time comparison for elapsed time
B) Earlier start date -
I) If end_time gt start_time
a) subtract dates to get number of days
b) multiply days by 24
c) subtract times to get extension
d) add extension to previous hour count
II) if end_time lt start_time
a) subtract dates to get number of days
b) if day difference = 1, you're under 24hrs
1) calculate distance from midnight on first day
2) calculate distance from midnight on second day
3) add both numbers
c) if difference gt 1, you're over 24hrs
1) calculate distance from midnight on first day
2) calculate distance from midnight on second day
3) add both numbers
4) multiply (difference - 1) by 24 and add to that total
Okay, that's the complicated way of doing it, but I -think- it covers all
the permutations. It's probably way more convoluted than necessary, but
it's how I, personally, would approach the problem if doing it for myself
and did not have access to a simple unix timestamp.
NOTE: This is alpha pseudocode, I did not write the real code (anytime
within the last 10 years, anyway--I know I did at one point between '93
and '95), and therefore there may actually be flaws in the pseudocode that
would normally get fixed when the real code was written and the flawed
logic became apparent as a bug. In general, I know this -kind- of approach
works, as I've used it before. Hopefully I got the details correct in this
quick reply.
PLUG FOR WISHLIST: UNIXTIME()
If you had that, you just keep your format in unix timestamp form, subtract
the two numbers, and do the appropriate divisions by 24, 60, and 60 to get
your total elapsed time segments, bing, bang, boom--you're done. No
worrying about meridians, as they become wholly irrelevant.
One of those times fP coders get it rougher time of it than needs be.
No pun actually intended, but I'll let it stand. :)
mark->
More information about the Filepro-list
mailing list