[REBOL] [ANN] time-in-digits.r 1.3.0
From: rchristiansen:pop:isdfa:sei-it at: 28-Dec-2000 16:53
Hooray!
I have updated my 'time-in-digits function so that it can be used with
the /precise refinement for 'now.
I use 'time-in-digits exhaustively, because it can be used to create
sequential session IDs over time and to create sequential file names
over time.
Because it can now handle the /precise refinement, it is very unlikely
you will create the same session ID for multiple connections to a CGI
interface (which was a possibility previously since more than one
person might submit to CGI within the same exact second. Now
there would only be a problem if more than one person might submit
to CGI within the same exact thousandth of a second.)
-Ryan
REBOL [
Title: "Date and time in digits"
Date: 28-Dec-2000
Name: 'time-in-digits
Version: 1.3.0
File: %time-in-digits.r
Author: "Ryan C. Christiansen"
Email: [norsepower--uswest--net]
Owner: "Ryan C. Christiansen"
Rights: "Copyright (C) Ryan C. Christiansen 2000"
Tabs: 4
Language: 'English
Purpose: {
Convert the date and time into a string of digits.
}
Comment: {
Use this function to create a string of digits denoting
the date and time. This is useful, especially for creating
sequential session IDs. If used with 'now to create a file
name, the newest file will always appear at the end of
a directory.
}
History: [
1.0.0 [12-June-2000 "posted to rebol.com" "Ryan"]
1.3.0 [28-Dec-2000 "updated for /precise refinement" "Ryan"]
]
Category: [util 2]
]
time-in-digits: func [
"Convert the date and time from 'now' into a string of digits."
sun-dial [date!] "The current date and time from 'now'"
][
year: to-string sun-dial/year
month: to-string sun-dial/month
if (length? month) < 2 [insert month "0"]
day: to-string sun-dial/day
if (length? day) < 2 [insert day "0"]
current-time: sun-dial/time
hour: to-string current-time/hour
if (length? hour) < 2 [insert hour "0"]
minutes: to-string current-time/minute
if (length? minutes) < 2 [insert minutes "0"]
seconds: to-string current-time/second
seconds-rounded: make integer! current-time/second
either current-time/second = seconds-rounded [
whole-seconds: seconds
partial-seconds: "000"
][
either seconds-rounded = 0 [
whole-seconds: "00"
time-string: make string! (reform current-time)
split-time: parse/all time-string "."
partial-seconds: second split-time
][
either current-time/second = 0 [
whole-seconds: "00"
partial-seconds: "000"
][
split-seconds: parse/all seconds "."
whole-seconds: first split-seconds
partial-seconds: second split-seconds
]
]
]
while [(length? whole-seconds) < 2][insert whole-seconds "0"]
while [(length? partial-seconds) < 3][append partial-seconds "0"]
rejoin [year month day hour minutes whole-seconds partial-seconds]
]