[REBOL] unix timestamp conversion? Re:(2)

2000-02-25 Thread prowsef

Will this script, submitted to the mailing list take into account
leap years etcor will there be a small descrepency?

Cheers

Francois


On Mon, 21 Feb 2000 [EMAIL PROTECTED] wrote:

 
  Anyone written a script to convert unix timestamps (is 950618412) to
  a usable rebol date and time format. 
  
  Cheers
  
  Francois
  
  
 
 Hi Francois:
 
 Try this.
 
 
 REBOL [
 Title: "Convert Epoch Time to Date"
 Author: "Ralph Roberts"
 File: %epoch-to-date.r
 Date: 21-Feb-2000
 Purpose: {converts UNIX Epoch time (seconds after 1-1-1970
   to current date and time }
 Example: {outputs "Epoch date 951142987 is 21-Feb-2000
   14:38:52 GMT or 9:38:52 Local" }
 ]
 
 epoch: 951142987
 
 days: divide epoch 86400
 
 days2: make integer! days
 
 time: (days - days2) * 24
 hours: make integer! time
 minutes: (time - hours) * 100
 minutes2: make integer! minutes
 seconds: make integer! (minutes - minutes2) * 100
 time2: make time! hours * 60) + minutes2) * 60) + seconds)
 
 prin ["Epoch date" epoch "is" 1-Jan-1970 + days2 time2]
 print [" GMT or" time2 + now/zone "Local"]
 



[REBOL] unix timestamp conversion? Re:(3)

2000-02-25 Thread rryost

Is the line

 prin ["Epoch date" epoch "is" 1-Jan-1970 + days2 time2]

perhaps supposed to have + inserted before 'time2.

The + operation for adding an integer number of days to a date does appear
to correctly take care of leap years, including that century years are not
leap years unless they are multiples of 400, (like 2000), in which case
they -are- leap years.  You can test this by

  1-jan-1999 + 365
== 1-Jan-2000
 1-jan-2000 + 365
== 31-Dec-2000
 1-jan-1000 + 365
== 1-Jan-1001

Russell [EMAIL PROTECTED]
- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, February 25, 2000 4:05 AM
Subject: [REBOL] unix timestamp conversion? Re:(2)


 Will this script, submitted to the mailing list take into account
 leap years etcor will there be a small descrepency?

 Cheers

 Francois


 On Mon, 21 Feb 2000 [EMAIL PROTECTED] wrote:

 
   Anyone written a script to convert unix timestamps (is 950618412) to
   a usable rebol date and time format.
  
   Cheers
  
   Francois
  
  
 
  Hi Francois:
 
  Try this.
 
 
  REBOL [
  Title: "Convert Epoch Time to Date"
  Author: "Ralph Roberts"
  File: %epoch-to-date.r
  Date: 21-Feb-2000
  Purpose: {converts UNIX Epoch time (seconds after 1-1-1970
  to current date and time }
  Example: {outputs "Epoch date 951142987 is 21-Feb-2000
  14:38:52 GMT or 9:38:52 Local" }
  ]
 
  epoch: 951142987
 
  days: divide epoch 86400
 
  days2: make integer! days
 
  time: (days - days2) * 24
  hours: make integer! time
  minutes: (time - hours) * 100
  minutes2: make integer! minutes
  seconds: make integer! (minutes - minutes2) * 100
  time2: make time! hours * 60) + minutes2) * 60) + seconds)
 
  prin ["Epoch date" epoch "is" 1-Jan-1970 + days2 time2]
  print [" GMT or" time2 + now/zone "Local"]
 




[REBOL] unix timestamp conversion? Re:

2000-02-21 Thread ralph


 Anyone written a script to convert unix timestamps (is 950618412) to
 a usable rebol date and time format. 
 
 Cheers
 
 Francois
 
 

Hi Francois:

Try this.


REBOL [
Title: "Convert Epoch Time to Date"
Author: "Ralph Roberts"
File: %epoch-to-date.r
Date: 21-Feb-2000
Purpose: {converts UNIX Epoch time (seconds after 1-1-1970
to current date and time }
Example: {outputs "Epoch date 951142987 is 21-Feb-2000
14:38:52 GMT or 9:38:52 Local" }
]

epoch: 951142987

days: divide epoch 86400

days2: make integer! days

time: (days - days2) * 24
hours: make integer! time
minutes: (time - hours) * 100
minutes2: make integer! minutes
seconds: make integer! (minutes - minutes2) * 100
time2: make time! hours * 60) + minutes2) * 60) + seconds)

prin ["Epoch date" epoch "is" 1-Jan-1970 + days2 time2]
print [" GMT or" time2 + now/zone "Local"]



[REBOL] unix timestamp conversion? Re:

2000-02-21 Thread ralph


 Anyone written a script to convert unix timestamps (is 950618412) to
 a usable rebol date and time format.

 Cheers

 Francois




And to do it the other way around, i.e. generate an Epoch date:


REBOL[
 ]

date: now

seconds: ((date - 1-1-1970) * 86400) + (date/time/hour * 3600) +
(date/time/minute * 60) + date/time/second

zone: now/zone

zone: zone/hour

zone: zone * 3600

seconds: seconds - zone ; minus a minus gives plus

print seconds  ; Epoch date