uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

datetime.tal (1953B)


      1 ( usage: uxncli datetime.rom )
      2 
      3 |10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
      4 |c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
      5 
      6 |0100
      7 
      8 @on-reset ( -> )
      9 	<print-date-num>
     10 	#0a .Console/write DEO
     11 	<print-date-str>
     12 	#0a .Console/write DEO
     13 	<print-time-num>
     14 	#0a .Console/write DEO
     15 	<print-doty>
     16 	#0a .Console/write DEO
     17 	#800f DEO
     18 	BRK
     19 
     20 @<print-date-num> ( -- )
     21 	.DateTime/year DEI2k <print-dec>
     22 	[ LIT "- ] .Console/write DEO
     23 	INC INC DEIk INC <print-dec-pad>
     24 	[ LIT "- ] .Console/write DEO
     25 	INC DEI !<print-dec-pad>
     26 
     27 @<print-date-str> ( -- )
     28 	;dict/date <print-str>
     29 	[ LIT2 00 -DateTime/dotw ] DEI #20 SFT ;week-txt ADD2 <print-str>
     30 	[ LIT2 20 ", ] #18 DEO
     31 	#18 DEO
     32 	[ LIT2 00 -DateTime/month ] DEI #20 SFT ;month-txt ADD2 <print-str>
     33 	#2018 DEO
     34 	[ LIT2 00 -DateTime/day ] DEI <print-dec>
     35 	[ LIT2 20 ", ] #18 DEO
     36 	#18 DEO
     37 	.DateTime/year DEI2 !<print-dec>
     38 
     39 @<print-time-num> ( -- )
     40 	;dict/time <print-str>
     41 	.DateTime/hour DEIk <print-dec-pad>
     42 	[ LIT2 ": 18 ] DEO
     43 	INC DEIk <print-dec-pad>
     44 	[ LIT2 ": 18 ] DEO
     45 	INC DEI !<print-dec-pad>
     46 
     47 @<print-str> ( str* -- )
     48 	&w ( -- )
     49 		LDAk #18 DEO
     50 		INC2 LDAk ?&w
     51 	POP2 JMP2r
     52 
     53 @<print-doty> ( -- )
     54 	;dict/doty <print-str>
     55 	.DateTime/doty DEI2
     56 	( >> )
     57 
     58 @<print-dec> ( short* -- )
     59 	#2710 [ LIT2r 00fb ]
     60 	&w ( -- )
     61 		DIV2k #000a DIV2k MUL2 SUB2 SWPr EQUk OVR STHkr EQU AND ?&>skip
     62 			DUP <emit-dec>
     63 			INCr &>skip
     64 		POP2 #000a DIV2 SWPr INCr STHkr ?&w
     65 	POP2r POP2 POP2 JMP2r
     66 
     67 @<print-dec-pad> ( byte -- )
     68 	#0a DIVk <emit-dec>
     69 	DIVk MUL SUB
     70 	( >> )
     71 
     72 @<emit-dec> ( byte -- )
     73 	LIT "0 ADD #18 DEO
     74 	JMP2r
     75 
     76 (
     77 @|assets )
     78 
     79 @week-txt
     80 	[
     81 	"Sun $1 "Mon $1 "Tue $1 "Wed $1
     82 	"Thu $1 "Fri $1 "Sat $1 ]
     83 
     84 @month-txt
     85 	[
     86 	"Jan $1 "Feb $1 "Mar $1 "Apr $1
     87 	"May $1 "Jun $1 "Jul $1 "Aug $1
     88 	"Sep $1 "Oct $1 "Nov $1 "Dec $1 ]
     89 
     90 @dict ( )
     91 	&date "The 20 "date 20 "is: 20 $1
     92 	&time "The 20 "time 20 "is: 20 $1
     93 	&doty "The 20 "day 20 "of 20 "the 20 "year 20 "is: 20 $1
     94