shithub: riscv

ref: c76cc12a1799ce214b07882eb6f4ab0906c0151b
dir: /sys/src/cmd/test/date.rc/

View raw version
#!/bin/rc

rfork en
cat /adm/timezone/GMT > /env/timezone

nl='
'

fn check {
	r=`$nl{../$O.$1 $2}
	if(! ~ $r $3){
		echo "$"r"
		echo "$"3"
		echo $status
		>[1=2] echo fail: $1 $2: got $r expected $3
		exit 'fail'
	}
}

# examples from manpage, and shuffles
rfork ne
check seconds '23 may 2011' 			1306108800
check seconds 'may 23 2011' 			1306108800
check seconds 'may 2011 23' 			1306108800
check seconds '23 2011 may' 			1306108800
check seconds '2011 may 23'			1306108800
check seconds '2011 23 may'			1306108800

# now with timezones
check seconds '23 may 2011 edt'			1306123200
check seconds '23 may 2011 gmt'			1306108800

# If the tz is present, the results should stay
# the same if we change zones.
@{
	rfork en
	cat /adm/timezone/US_Pacific >/env/timezone
	check seconds '23 may 2011 edt'			1306123200
	check seconds '23 may 2011 gmt'			1306108800
}

# now with all variations on times.
check seconds 'may 23 2011 0'			1306108800
check seconds 'may 23 2011 0:1'			1306108860
check seconds 'may 23 2011 0:1:2'		1306108862

# now with times and timezones
check seconds '23 may 2011 edt'			1306123200
check seconds '23 may 2011 gmt'			1306108800

# formats from ../$O.date(1)
check seconds 'Sun, 14 Jun 2020 22:08:48 -0700'	1592197728
check seconds 'Sun, 14 Jun 2020 -0700'		1592118000
check seconds '2020-06-14'			1592092800
check seconds '2020-06-14T22:14:17-07:00'	1592198057

# colloquial american format (eww)
check seconds '06/14/2020'			1592092800
check seconds '06/01/2020'			1590969600

# Do we transition at the right DST?
@{
	rfork en
	cat /adm/timezone/US_Eastern >/env/timezone
	check date 1710053999 'Sun Mar 10 01:59:59 EST 2024'
	check date 1710054000 'Sun Mar 10 02:00:00 EST 2024'
	check date 1710054001 'Sun Mar 10 03:00:01 EDT 2024'

	check date 1730617200 'Sun Nov  3 03:00:00 EDT 2024'
	check date 1730617201 'Sun Nov  3 02:00:01 EST 2024'
	check date 1730620800 'Sun Nov  3 03:00:00 EST 2024'
}

# Arizona has no DST
@{
	rfork en
	cat /adm/timezone/US_Arizona >/env/timezone
	check seconds 'Mon, Jun 21 17:38:02 MST 2020' 1592786282
}

# CET is a timezone with no hard-coded
# timezone name -- it should round trip
@{
	rfork en
	cat /adm/timezone/CET >/env/timezone
	tm=1592782682
	ds=`{../$O.date $tm}
	r=`{../$O.seconds $"ds}
	if(! ~ $tm $r)
		>[1=2] echo fail: CET: got $r expected $tm
}

# The other EST should also round trip.
@{
	rfork en
	cat /adm/timezone/Australia_ACT >/env/timezone
	tm=1592782682
	ds=`$nl{../$O.date $tm}
	r=`$nl{../$O.seconds $ds}
	if(! ~ $tm $r)
		>[1=2] echo fail: Austraila_ACT: got $r expected $tm
}
exit ''