flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > date/time macros 
Author 

wolf 23 Mar 2004, 07:34
hi,
I think there is a bug in the make_timestamp routine in fasm because there is a difference of up to two days in comparison to TimeDateFunctions calculated by GB32 for Windows depending on SystemTime. In the calculation, shouldn't it be: Code: DAY = DAY  (DAY73060)/(3*365+366)1 730 subtracts the first two years 1970 and 1971 1 takes into account the leap year 1972  60 takes into account that after 4 years plus 60 days there is a 29th of February The macro has to be changed as well, as the 29th of February in a Leap Year will not be calculated correctly. This is just a quick idea, maybe I'm wrong! wolf 

23 Mar 2004, 07:34 

Tomasz Grysztar 23 Mar 2004, 11:32
The macro is buggy, I have never dedicated enough time to fix it. However the make_timestamp gives me a good results (the same values as those given by Linux, which uses such time format internally)


23 Mar 2004, 11:32 

wolf 24 Mar 2004, 23:06
I wrote another macro:
Code: macro calcdate { REPLOOP = DAY / 365 repeat REPLOOP if YEAR mod 4 = 0 DAY = DAY  366 else DAY = DAY  365 end if YEAR = YEAR +1 end repeat if YEAR mod 4 = 0 months 31,29,31,30,31,30,31,31,30,31,30,31 else months 31,28,31,30,31,30,31,31,30,31,30,31 end if } DAY = %T / 86400 +1 YEAR = 1970 MONTH = 1 calcdate But when I change my system time to the 29.02.2004 the macro shows a difference of two days. And after I patched the timestamp routine with the above code, the macro gives correct results again. When you subtract timestamp1 (29.02.) from timestamp2 (24.03.) you get a number of seconds which roughly represent 26 days, which resembles the difference in the macro results. Sorry, but I still think there must be a bug in the timestamp routine. wolf 

24 Mar 2004, 23:06 

comrade 24 Mar 2004, 23:10
timestamp routine works fine, because it is used for PE header and in resource macros. I checked PE header in a program which explodes stamp correctely with correct date.


24 Mar 2004, 23:10 

Tomasz Grysztar 03 Apr 2004, 17:07
Here's the corrected macro:
Code: macro months [dayscount] { forward if DAY > dayscount DAY = DAYdayscount MONTH = MONTH+1 forward end if } TIME = %T DAY = TIME/(24*3600) DAY = DAY  (DAY+365)/(3*365+366) YEAR = 1970+DAY/365 DAY = DAY mod 365 + 1 MONTH = 1 if YEAR mod 4 = 0 FEBDAYS=29 else FEBDAYS=28 end if months 31,FEBDAYS,31,30,31,30,31,31,30,31,30,31 It should give you correct values for dates up to the year 2100. 

03 Apr 2004, 17:07 

comrade 04 Apr 2004, 03:10
Thanks!


04 Apr 2004, 03:10 

pelaillo 04 Apr 2004, 15:27
This one even after 2100...
Code: macro months [dayscount] { forward if DAY > dayscount DAY = DAYdayscount MONTH = MONTH+1 forward end if } TIME = %T DAY = TIME/(24*3600) DAY = DAY  (DAY+365)/(3*365+366) YEAR = 1970+DAY/365 DAY = DAY mod 365 + 1 MONTH = 1 if YEAR mod 4 = 0 if YEAR mod 100 = 0 if YEAR mod 400 = 0 FEBDAYS=29 else FEBDAYS=28 end if else FEBDAYS=29 end if else FEBDAYS=28 end if months 31,FEBDAYS,31,30,31,30,31,31,30,31,30,31 Gregorian's Calendar: The day after Oct 4, 1582 was Oct 15, 1582. Before reform, every 4 years were a leap year. Leap year if divisible by 4 and not by 100 Leap year if divisible by 100 and by 400 

04 Apr 2004, 15:27 

Tomasz Grysztar 04 Apr 2004, 16:19
But you are not taking into account the years divisible by 100 when they occur between 2000 and the year of timestamp.


04 Apr 2004, 16:19 

pelaillo 04 Apr 2004, 18:10
Because the years divisible by 4 and 100 and not by 400 are not leap.


04 Apr 2004, 18:10 

Tomasz Grysztar 04 Apr 2004, 20:30
So you should substract one form the count of days for each such year, that occurs between 1970 and the year you are calculating


04 Apr 2004, 20:30 

Aster!x 30 Jul 2004, 21:15
Maybe someone already tried to write such macro for fasm?
Code: date MACRO % FORC chr, @Date db "&chr" ENDM ENDM time MACRO % FORC chr, @Time db "&chr" ENDM ENDM 

30 Jul 2004, 21:15 

xanatose 19 Apr 2006, 21:16
Thank you for the macro
Here is a macro to get a string in the form YYY.MM.DD, this is usefull for version information. Code: macro datestring szName { common label szName db ((YEAR / 1000)+'0') db (((YEAR mod 1000) / 100) + '0') db (((YEAR mod 100) / 10) + '0') db ((YEAR mod 10) + '0') db '.' db ((MONTH / 10) + '0') db ((MONTH mod 10) + '0') db '.' db ((DAY / 10) + '0') db ((DAY mod 10) + '0') lenof.#szName = $  szName db 0 } I use this in the data section like this Code: ; for example APR 19, 2006 would be '2006.04.19',0 datestring szVersionString 

19 Apr 2006, 21:16 

vid 12 Feb 2007, 15:31
could someone extend this to also get current time ?


12 Feb 2007, 15:31 

comrade 04 Jul 2008, 04:51
What do you mean, "get current time" ? Isn't the timestamp %T itself, current time?


04 Jul 2008, 04:51 

vid 04 Jul 2008, 08:43
I was talking about macro to parse timestamp into symbolic constants (hour / min / sec)


04 Jul 2008, 08:43 

baldr 19 Sep 2008, 22:34
hour equ (%t / 3600) mod 24
min equ (%t / 60) mod 60 sec equ %t mod 60 All timestamps are UTC (GMT±0) 

19 Sep 2008, 22:34 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.