Date/Time
For a structured representation of time and date, Xoscript uses the Moment object. In case a new Moment object is printed on screen, the current date and time are shown:
Out write: Moment new, stop.
Might result in something like:
2020-10-10 12:16:39
It is also easy to read out the individual time components. So, for instance, if it is only necessary to know the current year, the message year can be sent to the moment and, in turn, the reply will be a Number object containing solely the year:
>> m := Moment new.
Out write: m year, stop.
[ Moment ] wait: [ Number ]
Example:
>> time := Moment new time.
Moment wait: 1.
>> time2 := Moment new time.
(time2 > time) true: { Out write: ['T1 < T2']. }.
Result:
automatically generated from test: #79
[ Moment ] zone: [ String ]
Example:
#Linux
>> t := Moment new.
t zone: ['Europe/Amsterdam'].
t year: 2020, month: 8, day: 2, hour: 21, minute: 2, second: 1.
>> a := t hour.
>> ams := t zone.
t zone: ['US/Hawaii'].
>> b := t hour.
>> hw := t zone.
Out
write: (
['It's diff in zone2 than in zone1']
zone1: ams,
zone2: hw,
diff: (
(b > a)
either: ['later'] or: ['earlier']
)
),
stop.
Result:
automatically generated from test: #570
[ Moment ] zone
Example:
# Linux
Out write: Moment zone, stop.
Result:
automatically generated from test: #571
[ Moment ] year: [ Number ]
Example:
>> x := Moment new.
x zone: ['UTC'].
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #572
[ Moment ] month: [ Number ]
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #573
[ Moment ] day: [ Number ]
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #574
[ Moment ] hour: [ Number ]
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #575
[ Moment ] minute: [ Number ]
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #576
[ Moment ] second: [ Number ]
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #577
[ Moment ] year
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #578
[ Moment ] month
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #579
[ Moment ] day
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #580
[ Moment ] hour
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #581
[ Moment ] minute
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #582
[ Moment ] second
Example:
>> x := Moment new.
x year: 2020.
x month: 8.
x day: 12.
x hour: 10.
x minute: 2.
x second: 1.
Out write: x year.
Out write: x month.
Out write: x day.
Out write: x hour.
Out write: x minute.
Out write: x second.
Result:
automatically generated from test: #583
[ Moment ] yearday
Example:
>> t := Moment new
year: 2020,
month: 1,
day: 2.
Out write: t yearday, stop.
Result:
automatically generated from test: #584
[ Moment ] weekday
Example:
>> t := Moment new
year: 2020,
month: 1,
day: 2.
Out write: t weekday, stop.
Result:
automatically generated from test: #585
[ Moment ] time
Example:
>> t := Moment new
year: 2020,
month: 1,
day: 2.
Out write: t time, stop.
Result:
automatically generated from test: #586
[ Moment ] copy
Example:
>> t := Moment new
year: 2020,
month: 1,
day: 2,
hour: 10,
minute: 0,
second: 1.
Out write: t, stop.
>> t2 := t copy.
Out write: t2, stop.
Result:
automatically generated from test: #587
[ Moment ] = [ Moment ]
Example:
>> m := Moment new year: 2070, month: 11, day: 1.
>> n := m copy.
Out write: (m = n), stop.
Out write: (m ≠ n), stop.
Out write: (m equals: m), stop.
Out write: (m equals: n), stop.
n month: 12.
Out write: (m ≠ n), stop.
Out write: (m = n), stop.
Result:
automatically generated from test: #588
[ Moment ] ≠ [ Moment ]
Example:
>> m := Moment new year: 2070, month: 11, day: 1.
>> n := m copy.
Out write: (m = n), stop.
Out write: (m ≠ n), stop.
Out write: (m equals: m), stop.
Out write: (m equals: n), stop.
n month: 12.
Out write: (m ≠ n), stop.
Out write: (m = n), stop.
Result:
automatically generated from test: #589
[ Moment ] week
Example:
>> t := Moment new
year: 2020,
month: 1,
day: 2,
hour: 10,
minute: 0,
second: 1.
Out write: t, stop.
Out write: t week, stop.
Result:
automatically generated from test: #590
[ Moment ] format: [ String ]
Example:
>> x := Moment new
year: 1981,
month: 1,
day: 5.
Out write: (x format: ['%a, %d %b %Y %H:%M:%S']), stop.
Result:
automatically generated from test: #626
[ Moment ] string
Example:
>> t := Moment new
year: 2020,
month: 1,
day: 2,
hour: 10,
minute: 0,
second: 1.
Out write: t, stop.
Out write: t string, stop.
Result:
automatically generated from test: #591
[ Moment ] iso-datetime
Example:
# build a moment
>> t := Moment new
zone: ['CET'],
year: 1990,
month: 1,
day: 2,
hour: 10,
minute: 11,
second: 12.
# print the moment as YYYY-MM-DD HH:II:SS
Out write: t iso-datetime, stop.
Result:
automatically generated from test: #663
[ Moment ] number
Example:
>> t := Moment new
year: 2020,
month: 1,
day: 2,
hour: 10,
minute: 0,
second: 1.
Out write: t, stop.
Out write: t number, stop.
Result:
automatically generated from test: #592
[ Moment ] add: [ Number ]
Example:
>> x := Moment new
year: 2020,
month: 1,
day: 2,
hour: 10,
minute: 0,
second: 1.
Out write: x, stop.
x add: 6 second.
Out write: x, stop.
x add: 5 minute.
Out write: x, stop.
x add: 4 hour.
Out write: x, stop.
x add: 3 day.
Out write: x, stop.
x add: 2 month.
Out write: x, stop.
x add: 1 year.
Out write: x, stop.
Result:
automatically generated from test: #593
[ Moment ] subtract: [ Number ]
Example:
>> x := Moment new
year: 2020,
month: 1,
day: 2,
hour: 10,
minute: 0,
second: 1.
Out write: x, stop.
x subtract: 6 second.
Out write: x, stop.
x subtract: 5 minute.
Out write: x, stop.
x subtract: 4 hour.
Out write: x, stop.
x subtract: 3 day.
Out write: x, stop.
x subtract: 2 month.
Out write: x, stop.
x subtract: 1 year.
Out write: x, stop.
Result:
automatically generated from test: #594
[ Moment ] new
Example:
>> t := None.
# you can control the time zone for
# parsing like this:
Moment zone: ['CET'].
t := Moment from: ['1981-02-03 04:05:06'].
Out write: t, stop.
# now using CEST time zone:
Moment zone: ['CEST'].
t := Moment from: ['1981-02-03 04:05:06'].
Out write: t, stop.
# error if string cannot be parsed
{ Moment from: ['1900']. } except: { None. }, start.
Result:
automatically generated from test: #662