this documentation is work-in-progress, edit here (md).

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 ] number »
[ Moment ] add: [ Number ] »
[ Moment ] subtract: [ Number ] »

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:

Server init.

>> x := Blob utf8: ['from utf8 string'].

x from: 0 length: 10, each: { :i :b
	Out write:
	['byte #'] + i + [' is: '] + b,
	stop.
}.

x free.
	

Result:

byte #0 is: 102
byte #1 is: 114
byte #2 is: 111
byte #3 is: 109
byte #4 is: 32
byte #5 is: 117
byte #6 is: 116
byte #7 is: 102
byte #8 is: 56
byte #9 is: 32

	

[ 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

	

[ Moment ] zone

Example:

# Linux
Out write: Moment zone, stop.

	

Result:

UTC

	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ 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
	

[ Moment ] yearday

Example:


>> t := Moment new
year: 2020,
month: 1,
day: 2.

Out write: t yearday, stop.

	

Result:

1

	

[ Moment ] weekday

Example:

>> t := Moment new
year: 2020,
month: 1,
day: 2.

Out write: t weekday, stop.
	

Result:

5

	

[ Moment ] time

Example:


>> t := Moment new
year: 2020,
month: 1,
day: 2.

Out write: t time, stop.
 
	

Result:

1577923200

	

[ 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

	

[ 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

	

[ 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

	

[ 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

	

[ 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

	

[ 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

	

[ 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

	

[ 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

	

[ 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