trancexx Posted November 1, 2008 Share Posted November 1, 2008 (edited) This can be done by dllcalling function or two from msvcrt.dll. Limitation of that way is that it cannot proceed negative EPOCH times and is limited to maximum year of 2038 (3000).Probably there is some other function inside some other dll since Javascript has this as built-in function and for example VBS can deal with "negative" times.Anyway, this is done without DllCall(). It is completley based on Date.au3 and functions inside it.- Why did I extract this out of Date.au3? Because this way these two functions are about 6-7 times faster than using Date.au3.- Speed compared to some other methods? Incredible! Impressive! omg!- Why? Date.au3 is very resourceful script. When I look at functions inside of it I'm starting to wonder if people who wrote them are humans at all? I have serious suspicions about Jos van der Zande. I think that he (it!) is some sort of artificial intelligence. I think that that entity has no form but exists in form that is far beyond our... something. I'm serious.Functions with small example:expandcollapse popupConsoleWrite("EPOCH time 1234567890 is " & _Epoch_decrypt(1234567890) & @CRLF) ConsoleWrite("Date 4712/12/31 23:59:59 is EPOCH " & _Epoch_encrypt("4712/12/31 23:59:59") & @CRLF) Func _EPOCH_decrypt($iEpochTime) Local $iDayToAdd = Int($iEpochTime / 86400) Local $iTimeVal = Mod($iEpochTime, 86400) If $iTimeVal < 0 Then $iDayToAdd -= 1 $iTimeVal += 86400 EndIf Local $i_wFactor = Int((573371.75 + $iDayToAdd) / 36524.25) Local $i_xFactor = Int($i_wFactor / 4) Local $i_bFactor = 2442113 + $iDayToAdd + $i_wFactor - $i_xFactor Local $i_cFactor = Int(($i_bFactor - 122.1) / 365.25) Local $i_dFactor = Int(365.25 * $i_cFactor) Local $i_eFactor = Int(($i_bFactor - $i_dFactor) / 30.6001) Local $aDatePart[3] $aDatePart[2] = $i_bFactor - $i_dFactor - Int(30.6001 * $i_eFactor) $aDatePart[1] = $i_eFactor - 1 - 12 * ($i_eFactor - 2 > 11) $aDatePart[0] = $i_cFactor - 4716 + ($aDatePart[1] < 3) Local $aTimePart[3] $aTimePart[0] = Int($iTimeVal / 3600) $iTimeVal = Mod($iTimeVal, 3600) $aTimePart[1] = Int($iTimeVal / 60) $aTimePart[2] = Mod($iTimeVal, 60) Return StringFormat("%.2d/%.2d/%.2d %.2d:%.2d:%.2d", $aDatePart[0], $aDatePart[1], $aDatePart[2], $aTimePart[0], $aTimePart[1], $aTimePart[2]) EndFunc Func _Epoch_encrypt($date) Local $main_split = StringSplit($date, " ") If $main_split[0] - 2 Then Return SetError(1, 0, "") ; invalid time format EndIf Local $asDatePart = StringSplit($main_split[1], "/") Local $asTimePart = StringSplit($main_split[2], ":") If $asDatePart[0] - 3 Or $asTimePart[0] - 3 Then Return SetError(1, 0, "") ; invalid time format EndIf If $asDatePart[2] < 3 Then $asDatePart[2] += 12 $asDatePart[1] -= 1 EndIf Local $i_aFactor = Int($asDatePart[1] / 100) Local $i_bFactor = Int($i_aFactor / 4) Local $i_cFactor = 2 - $i_aFactor + $i_bFactor Local $i_eFactor = Int(1461 * ($asDatePart[1] + 4716) / 4) Local $i_fFactor = Int(153 * ($asDatePart[2] + 1) / 5) Local $aDaysDiff = $i_cFactor + $asDatePart[3] + $i_eFactor + $i_fFactor - 2442112 Local $iTimeDiff = $asTimePart[1] * 3600 + $asTimePart[2] * 60 + $asTimePart[3] Return $aDaysDiff * 86400 + $iTimeDiff EndFuncWhat is really special about this functions is that they cover dates from -4712/12/31 23:59:59 (EPOCH -210831897601) to 2147483647/12/25 20:00:00 (EPOCH 67767976233000000). First date is nothing special but second one is far beyond other converters can convert. Far, far...edit: "comared" is not a word lol Edited September 6, 2013 by trancexx Espyre and PoojaKrishna 1 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
enaiman Posted November 11, 2008 Share Posted November 11, 2008 Thank you for sharing this It will help me great at the moment because I just wanted to start writing such a function myself and my Guardian Angel whispered me to search first on forum Lucky me I wouldn't mind seeing the dllcall version too SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Developers Jos Posted November 11, 2008 Developers Share Posted November 11, 2008 . I think that he (it!) is some sort of artificial intelligence. I think that that entity has no form but exists in form that is far beyond our... something. I'm serious.Excuse me ... you are referring to me as "it"?Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Szhlopp Posted November 11, 2008 Share Posted November 11, 2008 Excuse me ... you are referring to me as "it"?JosI think it is... LOL RegEx/RegExRep Tester!Nerd Olympics - Community App!Login UDFMemory UDF - "Game.exe+753EC" - CE pointer to AU3Password Manager W/ SourceDataFiler - Include files in your au3!--- Was I helpful? Click the little green '+' Link to comment Share on other sites More sharing options...
trancexx Posted November 11, 2008 Author Share Posted November 11, 2008 Thank you for sharing this It will help me great at the moment because I just wanted to start writing such a function myself and my Guardian Angel whispered me to search first on forum Lucky me I wouldn't mind seeing the dllcall version too $epoch_time = 1234567890 $aCall = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $epoch_time) ConsoleWrite("EPOCH time = " & $epoch_time & @CRLF) ConsoleWrite("EPOCH time converted to your timezone time = " & $aCall[0] & @CRLF) Can be used for 0 < $epoch_time < 2147483647 @AI (a.k.a. Jos); What? You're gonna X-ray me now or something? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
GEOSoft Posted November 11, 2008 Share Posted November 11, 2008 Excuse me ... you are referring to me as "it"?JosAnd he/she/it went so far as to suggest that your intelligence was artificial. Ik zou zeggen dat een klap in het gezicht. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Developers Jos Posted November 11, 2008 Developers Share Posted November 11, 2008 (edited) @AI (a.k.a. Jos);What? You're gonna X-ray me now or something?That would be a too friendly treatment Ik zou zeggen dat een klap in het gezicht.Yes... that's it for sure! Edited November 11, 2008 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
trancexx Posted November 11, 2008 Author Share Posted November 11, 2008 And he/she/it went so far as to suggest that your intelligence was artificial. Ik zou zeggen dat een klap in het gezicht.You would. Wouldn't you? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Developers Jos Posted November 11, 2008 Developers Share Posted November 11, 2008 You would. Wouldn't you?Don't think you translated that correctly when you make this remark. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
trancexx Posted November 11, 2008 Author Share Posted November 11, 2008 Don't think you translated that correctly when you make this remark.I was just using "argumentum ad hominem" (google?) for some fire.You ruined it now! ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
enaiman Posted November 11, 2008 Share Posted November 11, 2008 $epoch_time = 1234567890 $aCall = DllCall("msvcrt.dll", "str:cdecl", "ctime", "int*", $epoch_time) ConsoleWrite("EPOCH time = " & $epoch_time & @CRLF) ConsoleWrite("EPOCH time converted to your timezone time = " & $aCall[0] & @CRLF) Can be used for 0 < $epoch_time < 2147483647 Sweet Thanks alot. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
taz742 Posted October 19, 2009 Share Posted October 19, 2009 (edited) Thanks a lot trancexx for this useful unix timestamp encode/decode functions Edited October 19, 2009 by taz742 Link to comment Share on other sites More sharing options...
trancexx Posted January 18, 2010 Author Share Posted January 18, 2010 Very nice, trancexx, I've been looking for an alternative to the limited range of msvcrt.dll.There is something wrong with your decrypt function though.A timestamp of 1263769500 returns a invalid date of 2009/13/17 23:05:00.You are right.But I would lie if I tell you I didn't know that Corrected it a long ago but didn't post here. Corrected can be found inside the script called ResourcesViewerAndCompiler.au3.Function there is called _EpochDecrypt. It was just a touch. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
jchd Posted January 30, 2010 Share Posted January 30, 2010 May I add a little reminder to those that could be tempted to use trancexx code for applications where leap seconds matter (stock operations, remote auctions, documents timestamping, astronomy and the like) without asking themselves the right questions. Of course, this is a general remark and is in no way specific to what trancexx kindly shares with us. You need to determine exactly which taste of Unix epoch you have/want, which time scale you are converting to/from and which local legislation you need to take care of, in cases where placing a point in time makes a big difference if it falls that day/month/year or the next. AFAIK there can be up to 26 (no, not 24) seconds of difference between legal and official time. Also trying to place a time point more than 6 months in future within a few seconds is almost impossible. It's possible that those leap seconds will be suppressed completely someday, but until this happens (2013?) some of us will have to manipulate time with great care on such demanding occasions. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
ABV Posted October 18, 2011 Share Posted October 18, 2011 An EPOC of 0, seems to give a date in 1969! Link to comment Share on other sites More sharing options...
KaFu Posted October 18, 2011 Share Posted October 18, 2011 Corrected it a long ago but didn't post here. Corrected can be found inside the script called Function there is called _EpochDecrypt. It was just a touch. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
czardas Posted October 19, 2011 Share Posted October 19, 2011 (edited) I read the preamble and the rest. Interesting bit of code trancexx. I designed a front end, what do you think? It does have something to do with measuring time, honest!EditI just looked at how you are using comparison operators alongside mathematical operators in lines 26 and 27. That's something new to me. Your example is appreciated. Thanks. Edited October 20, 2011 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
trancexx Posted October 20, 2011 Author Share Posted October 20, 2011 I read the preamble and the rest. Interesting bit of code trancexx. I designed a front end, what do you think? It does have something to do with measuring time, honest! What do you think I think? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
JohnOne Posted October 20, 2011 Share Posted October 20, 2011 (edited) I think he thinks you think that he thinks.... wait, forget that. Whats an epoch? EDIT: Is it off star wars? Edited October 20, 2011 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted October 20, 2011 Share Posted October 20, 2011 Since I figured you were encrypting time, I though there was a chance you might find it amusing. I'm sure you're going to tell me anyway. I'm not sure what are the real applications for unix time are, so forgive me for showing ignorance. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now