This documentation is work-in-progress, we are working very hard to improve it. If you wish to help: edit here (md).
Translations: Spanish, Dutch

Date/Time

sections in this chapter:
[ Moment ] wait: [ Number ]
[ Moment ] zone: [ String ]
[ Moment ] zone
[ Moment ] year: [ Number ]
[ Moment ] month: [ Number ]
[ Moment ] day: [ Number ]
[ Moment ] hour: [ Number ]
[ Moment ] minute: [ Number ]
[ Moment ] second: [ Number ]
[ Moment ] year
[ Moment ] month
[ Moment ] day
[ Moment ] hour
[ Moment ] minute
[ Moment ] second
[ Moment ] yearday
[ Moment ] weekday
[ Moment ] time
[ Moment ] copy
[ Moment ] = [ Moment ]
[ Moment ] ≠ [ Moment ]
[ Moment ] week
[ Moment ] format: [ String ]
[ Moment ] string
[ Moment ] iso-datetime
[ Moment ] number
[ Moment ] add: [ Number ]
[ Moment ] subtract: [ Number ]
[ Moment ] new

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:

T1 < T2
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:

It's earlier in US/Hawaii than in Europe/Amsterdam
automatically generated from test: #570

[ Moment ] zone

Example:

# Linux
Out write: Moment zone, stop.

Result:

UTC
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
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:

20208121021
automatically generated from test: #583

[ Moment ] yearday

Example:


>> t := Moment new
year: 2020,
month: 1,
day: 2.
Out write: t yearday, stop.

Result:

1
automatically generated from test: #584

[ Moment ] weekday

Example:

>> t := Moment new
year: 2020,
month: 1,
day: 2.
Out write: t weekday, stop.

Result:

5
automatically generated from test: #585

[ Moment ] time

Example:


>> t := Moment new
year: 2020,
month: 1,
day: 2.
Out write: t time, stop.

Result:

1577923200
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:

2020-01-02 10:00:01
2020-01-02 10:00:01
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:

True
False
True
False
True
False
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:

True
False
True
False
True
False
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:

2020-01-02 10:00:01
0
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:

Mon, 05 Jan 1981 00:00:00
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:

2020-01-02 10:00:01
2020-01-02 10:00:01
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:

1990-01-02 10:11:12
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:

2020-01-02 10:00:01
1577959201
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:

2020-01-02 10:00:01
2020-01-02 10:00:07
2020-01-02 10:05:07
2020-01-02 14:05:07
2020-01-05 14:05:07
2020-03-05 14:05:07
2021-03-05 14:05:07
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:

2020-01-02 10:00:01
2020-01-02 09:59:55
2020-01-02 09:54:55
2020-01-02 05:54:55
2019-12-30 05:54:55
2019-10-30 05:54:55
2018-10-30 05:54:55
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:

1981-02-03 03:05:06
1981-02-03 04:05:06
automatically generated from test: #662