AutoHotkey Community

It is currently May 27th, 2012, 10:22 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: July 30th, 2007, 3:33 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Finally I have completed the slower version which consumes 200ms at the maximum permissible dates:

Code:
SetBatchLines -1

B=16010101000000      ; Minimum date supported
E=99981231235959      ; Maximum date supported

ATC := A_TickCount
AGE := AGE( B, E )

MsgBox, 64, % A_TickCount-ATC " ms", B: %B%`nE: %E%`n`n%AGE%

Return

#Z::RELOAD




AGE( B, E )                            {
  Y:=0, M:=0, D:=0,  Feb29 := SubStr(B,1,4) . "0229235959"

    dYear := B > Feb29 ? 365 * 86400 : LDOY(B) * 86400
    If DateDiff(B,E) >= dYear
       B:=DateAdd(B,dYear)  ,   Y:=Y+1

    Loop   {
              sYear := LDOY(B) * 86400
              If DateDiff(B,E) >= sYear
                 B:=DateAdd(B,sYear)  ,   Y:=Y+1
              Else Break
  } Loop   {
              sMonth := LDOM(B) * 86400
              If DateDiff(B,E) >= sMonth
                 B:=DateAdd(B,sMonth) ,   M:=M+1
              Else Break
  } Loop   {
              If DateDiff(B,E) >= 86400
                 B:=DateAdd(B,86400)  ,   D:=D+1
              Else Break
           }
  Remainder := dateAdd("16010101",dateDiff(B,E))
  FormatTime, HMS, %Remainder%, HH:mm:ss
 Return SubStr("000" Y,-3) "/" SubStr("0" M,-1) "/" SubStr("0" D,-1) " " HMS
}

; Dependencies

DateDIFF( B, E, U="S" )                {                                          ; EnvSub
  E-=%B%,%U%
 Return E
}
 
DateADD( Dt, V, U="S" )                {                                          ; EnvAdd
  Dt+=%V%,%U%
 Return Dt
}

LDOY( Dt )                             {                                ; Last Day of Year
  Year:=SubStr(Dt,1,4), Days:=Year+1
  Days-=%Year%,D
 Return Days
}

LDOM( Dt )                             {                               ; Last Day of Month
  M1:=SubStr(Dt,1,6), M2:=M1
  M2+=31,D             
  M2:=SubStr(M2,1,6)
  M2-=%M1%,D         
 Return M2
}


Please suggest any improvements. I will use this function to compare results with the faster versions.

:)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, robotkoer and 64 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group