flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > date/time macros

Author
Thread Post new topic Reply to topic
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 27 Feb 2004, 16:50
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?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 27 Feb 2004, 16:50
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
wolf



Joined: 28 Sep 2003
Posts: 11
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 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
Post 23 Mar 2004, 07:34
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
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)
Post 23 Mar 2004, 11:32
View user's profile Send private message Visit poster's website Reply with quote
wolf



Joined: 28 Sep 2003
Posts: 11
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    
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
Post 24 Mar 2004, 23:06
View user's profile Send private message Reply with quote
comrade



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

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 24 Mar 2004, 23:10
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 03 Apr 2004, 17:07
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. Wink
Post 03 Apr 2004, 17:07
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 04 Apr 2004, 03:10
Thanks!

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 04 Apr 2004, 03:10
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 04 Apr 2004, 15:27
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
Post 04 Apr 2004, 15:27
View user's profile Send private message Yahoo Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
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.
Post 04 Apr 2004, 16:19
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 04 Apr 2004, 18:10
Because the years divisible by 4 and 100 and not by 400 are not leap.
Post 04 Apr 2004, 18:10
View user's profile Send private message Yahoo Messenger Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
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
Post 04 Apr 2004, 20:30
View user's profile Send private message Visit poster's website Reply with quote
Aster!x



Joined: 16 Jul 2004
Posts: 26
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    
Post 30 Jul 2004, 21:15
View user's profile Send private message Reply with quote
xanatose



Joined: 09 Jan 2004
Posts: 57
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
    
Post 19 Apr 2006, 21:16
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 12 Feb 2007, 15:31
could someone extend this to also get current time ?
Post 12 Feb 2007, 15:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
comrade 04 Jul 2008, 04:51
What do you mean, "get current time" ? Isn't the timestamp %T itself, current time?
Post 04 Jul 2008, 04:51
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Jul 2008, 08:43
I was talking about macro to parse timestamp into symbolic constants (hour / min / sec)
Post 04 Jul 2008, 08:43
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
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) Wink
Post 19 Sep 2008, 22:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.