-
Notifications
You must be signed in to change notification settings - Fork 1
/
datetime.red
79 lines (65 loc) · 1.93 KB
/
datetime.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Red [
Title: "DateTime"
Origin: ".system.libraries.datetime.red"
]
.today: function [/to-string][
unless to-string [return now]
return .get-string-date now
]
today: :.today
.get-string-date: function [>the-date /separator >separator][
unless separator [
>separator: "."
]
year: pad-left >the-date/year 2
month: pad-left >the-date/month 2
day: pad-left >the-date/day 2
; hour: pad-left >the-date/time/hour 2
; minute: pad-left >the-date/time/minute 2
; second: pad-left >the-date/time/second 2
hms: .get-string-time/separator >the-date/time >separator
;return rejoin reduce [year "." month "." day "_" hour "." minute "." second]
return rejoin reduce [year >separator month >separator day "_" hms]
]
get-string-date: :.get-string-date
get-date-string: :.get-string-date
.get-string-time: function [>the-time /hour /minute /second /separator >separator][
unless separator [
>separator: "."
]
hours: pad-left >the-time/hour 2
if hour [return hours]
minutes: pad-left >the-time/minute 2
if minute [
either hour [
return rejoin reduce [hours >separator minutes]
][
return minutes
]
]
seconds: pad-left >the-time/second 2
if second [
either hour [
return rejoin reduce [hours >separator minutes >separator seconds]
][
either minute [
return rejoin reduce [minutes >separator seconds]
][
return seconds
]
]
]
return rejoin reduce [hours >separator minutes >separator seconds]
; if hour [
; return pad-left time/hour 2
; ]
; if minute [
; return pad-left time/minute 2
; ]
; if second [
; round/to
; return pad-left (round/to (time/second) 1) 2
; ]
]
get-string-time: :.get-string-time
get-time-string: :.get-string-time