home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
200-299
/
ff239.lzh
/
JGoodies
/
Brunjes
/
Date&Time
< prev
next >
Wrap
Text File
|
1989-08-21
|
4KB
|
124 lines
\
\ Date and Time words (uses AmigaDOS DateStamp facility)
\
\ Author: Roy E. Brunjes 17 August 1988
\
\ Load this code then to test, enter:
\ .TIME$ ( to show formatted time )
\ .DATE$ ( to show formatted date )
Anew TASK-Date&Time
CREATE MONTHS ( # days per month in bytes )
HEX 1F1C1F1E , 1F1E1F1F , 1E1F1E1F ,
DECIMAL
50 CONSTANT Ticks/Sec ( # Ticks in 1 Second )
60 CONSTANT Secs/Min ( # Seconds in 1 Minute )
Secs/Min 60 * CONSTANT Secs/Hour ( # Seconds in 1 Hour )
Secs/Hour 12 * CONSTANT Secs/12Hours ( # Seconds in 12 Hours )
Secs/12Hours 2 * CONSTANT Secs/Day ( # Seconds in 1 Day )
Variable Current.Time 0 , 0 , \ Note this is 3 32-bit words
: MyLoadTime ( adr -- ) >ABS CALL dos_lib datestamp DROP ;
: @CLOCK ( -- ticks minutes days ) \ Return time since 01 Jan 78
Current.Time myloadtime
Current.Time cell+ cell+ @ ( ticks since last minute )
Current.Time cell+ @ ( minutes since midnight )
Current.Time @ ( days since 01/01/78 )
;
: DAYS> ( # of days since 01 Jan 78 -- Year Day Month )
730 - ( Jump to leap year 1980 )
1461 /MOD 4 * 1980 + ( Stack: Day Year )
SWAP DUP 60 < ( Is this a leap year? )
IF ( If so, a special case )
DUP 31 <
IF 1
ELSE 31 - 2
THEN
ELSE
1- 365 /MOD ROT + SWAP
13 1
DO
I 1- Months + C@ 2DUP <
IF DROP I LEAVE
ELSE -
THEN
LOOP
THEN ( Year Day-1 Month )
SWAP 1+ SWAP ;
: Hold.Month ( month# -- formats month into date string )
1- 4 *
" -Jan-Feb-Mar-Apr-May-Jun-Jul-Aug-Sep-Oct-Nov-Dec-" ( length = 49 )
1+ + dup 4 + -do i c@ hold -1 +loop ;
: Fmt.Date$ ( #Days -- addr\cnt )
No-Commas Days> >R \ Put month on return stack
100 * \ Prepare to create ddyy string
\ (shift dd 2 places to left)
SWAP 1900 - \ Convert to 2-digit year
+ \ Convert to ddyy numeric string
S->D <# # # \ Convert yy portion
R> Hold.Month \ Convert to string-based month
# # #> \ Convert date to string
Commas ;
: Get.Date$ ( addr -- ) \ Put date string at addr (no count byte set)
\ (date string is 9 bytes long).
>R @CLOCK
Fmt.Date$
R> SWAP
CMOVE 2DROP ;
: .Date$ ( --- ) @Clock Fmt.Date$ TYPE 2DROP ;
\ Words for handling time-related things
: (:00) ( d -- ) \ Internal word used for formatting times
# 6 BASE ! # DECIMAL ASCII : HOLD ;
: Fmt.Time$ ( #seconds -- addr\cnt )
\
\ This confusing word builds an ASCII string for typing that will be the
\ time. It builds the string from right to left.
\
No-Commas
BASE @ >R ( Save existing BASE )
DECIMAL
<# ASCII m HOLD ( Rightmost char is a 'm' )
DUP Secs/12Hours < NOT ( Is it AM or PM? TRUE if PM )
IF ASCII p HOLD ( Put the 'p' before the 'm' )
Secs/12Hours 2DUP
Secs/Hour +
1- WITHIN? NOT ( If past noon: - 12 hrs )
IF Secs/12Hours - THEN
ELSE ( It is am, not pm )
ASCII a HOLD ( Put the 'a' before the 'm' )
THEN
BL HOLD
S->D (:00) (:00) # # ( Finish up the formatting )
#> ( Push string addr & count )
R> BASE ! ( Restore old BASE )
Commas
;
: Seconds ( -- #Seconds )
@CLOCK DROP
60 * SWAP
Ticks/Sec 2/
+ ( Round up to next second )
Ticks/Sec W/ + ;
: Get.Time$ ( addr -- ) \ Note: Time string is 11 characters
Seconds Fmt.Time$ ROT SWAP CMOVE ;
: .Time$ ( --- ) Seconds Fmt.Time$ TYPE ;