Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

How to scale Date-Time properly in REBOL?

 [1/4] from: jason:cunliffe:verizon at: 13-Jan-2002 9:00

Hi I need robust date-time handling, for referencing a wide range of timestamped data, historical, ancient, modern, up to and including current internet messaging logfiles etc.. Ideally looking for REBOL implementation of the rich feature set offered by Marc-André Lemburg's superb mxDateTime module for Python: among the problems I have with REBOL's datetime:
>> n: now
== 13-Jan-2002/8:48-5:00
>> n/year
== 2002
>> n/year: 1400
== 1400
>> n
== 13-Jan-1400/8:48-5:00
>> n/year: -1400
== -1400
>> n
== 13-Jan-64136/8:48-5:00 oops! Is this just a bug, or is there a real prbolem in REBOL adressing historical data? How to fix this? Has anyone already written a more versatile datetime object which can override the defaults? Am I going to have to create my own date-time format and bypass rebols? If so any suggestiosn about how best to do this.. create a new datatype/protocol? what do you suggest? many thanks ./Jason

 [2/4] from: brett:codeconscious at: 14-Jan-2002 19:26

Hi Jason,
> what do you suggest?
You're probably not going to like this :) Ask [feedback--rebol--com]. *ducks* Other than that I've include just a few miscellanous functions I've used (not very often) just to feel like I contributed something of even small use: ; ; Datetimes ; subtract-datetimes: function [ "Subract one date from another returning time between them." a [date!] b [date!] ] [delta-days delta-hhmmss a-hhmmss b-hhmmss] [ delta-days: subtract a/date b/date a-hhmmss: either a/time [a/time] [00:00:00] b-hhmmss: either b/time [b/time] [00:00:00] return add (multiply 24:00:00 delta-days) (subtract a-hhmmss b-hhmmss) ] ; ; Dates ; add-months: function [ "Add months to a date." date [date!] months [integer!] ] [result-date delta-years delta-months] [ delta-years: to-integer divide months 12 delta-months: remainder months 12 if lesser? delta-months 0 [ delta-years: subtract delta-years 1 delta-months: add delta-months 12 ] result-date: date result-date/year: add result-date/year delta-years result-date/month: add result-date/month delta-months return result-date ] first-day?: func [ "First day of the month." date "Specifies a month using an sample date." [date!] ][ to-date reduce[1 date/month date/year] ] days-in-month?: func [ "Number of days in the month." date "Specifies a month using an sample date." [date!] ][ subtract to-date reduce[1 date/month + 1 date/year] first-day? date ] last-day: last-day?: func [ "Last day of the month." date "Specifies a month using an sample date." [date!] ][ to-date reduce [ days-in-month? date date/month date/year] ] Cheers, Brett.

 [3/4] from: rebol:optushome:au at: 14-Jan-2002 22:35

> ; Dates > ;
<<quoted lines omitted: 14>>
> return result-date > ]
Maybe I'm missing something there, Brett, but that looks like a bit of overkill? add-months: func [ "Add months to a date." date [date!] months [integer!] ][ date/month: date/month + months date ] Cheers, Allen K

 [4/4] from: brett::codeconscious::com at: 14-Jan-2002 23:43

Hi Allen,
> Maybe I'm missing something there, Brett, but that looks like a bit of > overkill?
<<quoted lines omitted: 6>>
> date > ]
Inappropriate overkill is a bad habit of mine :) In this case I think it was due to bugs in date operations, similar to what Jason has found. It eludes me now which versions are affected. Brett.

  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted