flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > date/time macros
Author

Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
Privalov wrote these macros:
Code:
```macro months [dayscount]
{
forward
if DAY > dayscount
DAY = DAY-dayscount
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
months 31,28,31,30,31,30,31,31,30,31,30,31

TIME = TIME mod (24*3600)
HOUR = TIME/3600
MINUTE = (TIME mod 3600)/60
SECOND = (TIME mod 3600) mod 60
DATE equ (DAY / 10 + '0'),(DAY MOD 10 + '0'),".",(MONTH / 10 + '0'),(MONTH MOD 10 + '0'),".",(YEAR / 1000 + '0'),((YEAR / 100) MOD 10 + '0'),((YEAR / 10) MOD 10 + '0'),(YEAR MOD 10 + '0')
TIME equ (HOUR / 10 + '0'),(HOUR MOD 10 + '0'),":",(MINUTE / 10 + '0'),(MINUTE MOD 10 + '0'),":",(SECOND / 10 + '0'),(SECOND MOD 10 + '0')    ```

It breaks down timestamp into individual fields. Today is 27th, but it says 25th. It worked before though, only now I notice there is problem. I am not too bright to figure out what is wrong. Does anyone have any idea?

_________________
27 Feb 2004, 16:50
wolf

Joined: 28 Sep 2003
Posts: 11
wolf
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 TimeDate-Functions calculated by GB32 for Windows depending on SystemTime.

In the calculation, shouldn't it be:
Code:
```DAY = DAY - (DAY-730-60)/(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

Joined: 16 Jun 2003
Posts: 7871
Location: Kraków, Poland
Tomasz Grysztar
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

Joined: 28 Sep 2003
Posts: 11
wolf
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    ```
The macro is probably buggy and you are right: the timestamp is ok.

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

Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
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

Joined: 16 Jun 2003
Posts: 7871
Location: Kraków, Poland
Tomasz Grysztar
Here's the corrected macro:
Code:
```macro months [dayscount]
{
forward
if DAY > dayscount
DAY = DAY-dayscount
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

Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
Thanks!

_________________
04 Apr 2004, 03:10
pelaillo
Missing in inaction

Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
This one even after 2100...

Code:
```macro months [dayscount]
{
forward
if DAY > dayscount
DAY = DAY-dayscount
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

Joined: 16 Jun 2003
Posts: 7871
Location: Kraków, Poland
Tomasz Grysztar
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
Missing in inaction

Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
Because the years divisible by 4 and 100 and not by 400 are not leap.
04 Apr 2004, 18:10
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7871
Location: Kraków, Poland
Tomasz Grysztar
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

Joined: 16 Jul 2004
Posts: 26
Aster!x
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

Joined: 09 Jan 2004
Posts: 57
xanatose
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
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
could someone extend this to also get current time ?
12 Feb 2007, 15:31

Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
What do you mean, "get current time" ? Isn't the timestamp %T itself, current time?
04 Jul 2008, 04:51
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
I was talking about macro to parse timestamp into symbolic constants (hour / min / sec)
04 Jul 2008, 08:43
baldr

Joined: 19 Mar 2008
Posts: 1651
baldr
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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum