Tenth of seconds between dates
fuser
Posts: 3
Hey Guys,
I've some problem with the managing of the dates, I would like to know how many second's there is between a date and an other.
Is there any function in netlink that answer you how many seconds is past from the Unix universal date? in that case I can do the difference between the two answers...
Does Anyone got an Idea???
Thanks so much
I've some problem with the managing of the dates, I would like to know how many second's there is between a date and an other.
Is there any function in netlink that answer you how many seconds is past from the Unix universal date? in that case I can do the difference between the two answers...
Does Anyone got an Idea???
Thanks so much
0
Comments
Jeff
Perhaps the problem for fuser is establishing the numbers of days/seconds of today date:time given as strings 'mm/dd/yy' 'hh:mm:ss' in reference with unix zero time, of a similar form.
I am sure that will be just a step from translating your logic further and parsing/converting the relevant chars to integers.
http://en.wikipedia.org/wiki/Year_2038_problem
Yes, I believe you are as it?s not as easy as it sounds. If I?m reading the original post correctly, fuser wants to know the difference in seconds between 2 dates. For example how many seconds are there between say March 10, 2009 at 11:30 PM and midnight July 4, 2020? Or how many seconds are there from right now until your 60th birthday? Or how many seconds have you been alive?
Other languages have built in functions that calculate that for you like the DateDiff() function in VBScript. You pass the function 2 dates along with a time interval (seconds or days or weeks, etc.) and the function will return the number of whatever-interval-you-passed-in between the two dates. So if you want to find out how many days are left in the year or how many weeks until Christmas you?re just one function call away.
Netlinx has no such built in function (sure wish it did) so the standard way to calculate the number of seconds between two dates is to first put them both on common ground i.e. find out how many seconds have elapsed since midnight Jan 1, 1970 (Unix time) for each of those dates and then do the simple math from there. I assume the file posted by Auser has the functions needed to calculate Unix time.
If anyone from AMX is listening in is there any chance of getting a DateDiff() function for Netlinx? And if the answer is yes, how many seconds away are we from getting it?
If I new that the Cafe Duet files were fixed in update, I would try it out for you, but I need to call tech support and verify this first as I am in the middle of some code development and can't afford the problems again
Jeff
Yep, what Joe said.
Thank you for yours answers, Joe has understand the problem.
I know that in one day there is 60 minutes and in every minutes there is 60 seconds :-)
But the problem is the difference between 2 different dates as Joe Said, so do you think that the only way to do that is reporting all the dates in Unix Time and do the difference between the two dates?
I'm not an expert of cafe duet can I do just a compilate function that will be included in the module?
Thanks a lot
BYe
Hy Guys,
I've solved My Problem Using the library that Auser has posted, thanks a lot to everyone, specialy to Auser an Joe.
Bye, Bye.
fuser
// Commands - Will return UnixTime based on the masters time, with the current timezone shift set in the master.
SEND_COMMAND 41001,'GET_UNIX_TIME-NOW'
// Will return Unix Time with current localtime indicating timezone shift (-500)
SEND_COMMAND 41001,'GET_UNIX_TIME-03/11/2009,18:31:08,-0500'
Instead of doing something straight forward and simple like:
seconds = DateDiff(blahblah)
IF (seconds > whatever) do this
We have to do a SEND_COMMAND and then setup some sort of callback for the return SEND_COMMAND from Duet and then continue on from where we left off. That kind of coding can get real ugly real fast.
Duet and modules in general are fine for things like comm drivers and the like but it sure doesn?t seem practical for this type of situation. A situation that calls for a plain old function. Maybe I?m not thinking it through properly.
I wasn't trying to say that a Duet module was/is the best answer, it was just an answer that I thought of at the time. Had Auser not posted the necessary code to do the calculations, I was operating from the perspective that using the tested functionality of the function from duet would be quicker and (possibly) more reliable than writing your own function. This was after I fully understood the problem Dealing with all of the leap years and leap seconds and what-not seemed like a good place to miss a value or something that would not necessarily break the function, but make it act slightly erratic at the perfect wrong time
I have given up on hoping that AMX will add functions and/or fix functionality in NetLinx (see switch()..case thread). I think these requests fall into the "less than 1% of the programmers using NetLinx would/can use this, so why invest the time and money" category. I would be happy if they finished developing Cafe Duet to make it easier to code entirely in Duet. (I know it's possible right now ... save one line of netlinx code)
The reason I like the idea of Cafe Duet development over NetLinx is simple. Duet is based enough on Java to work with code that others have developed which allows me to purchase/find code from people who do not even know what an AMX processor is. There is also the fact that Duet is implementing a language being developed by company other than AMX and the language is constantly being optimized and improved. Development of the base code features is not restricted to only what AMX develops and integrates.
And I notice that I am starting to stray off topic, so I will stop now. If anyone is interested in discussing this further, we can start a new thread.
Jeff
My goal in posting the duet module/code example was not to say, this is the way to deal with this situation. It was to say, yes duet has some nice features and it is very easy to use them. In addition, if you find this useful, you can use it.
On another note, call back function may tend to be a little slower then calling a function. They can also be very valuable in programming very complex project where the function have to perform time consuming processing. In this case, off-loading some of these more time consuming processes into duet can free up NetLinx to continue with life while waiting for the call back information.
On a side note, RMS Development Kit comes with a TimeDateLib.axi. It provides some neat features and could help get the information your looking for, did not really look into it real deeply.
Paul