CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to Convert Date And Time To System Elapse Tick

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

How to Convert Date And Time To System Elapse Tick
PostPosted: Thu Nov 18, 2010 12:15 pm     Reply with quote

Hi,

I am looking for a sample code to Convert Date And Time To system Elapse Tick. Memory is very limited. Please help.

Thanks.
Howard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 18, 2010 1:05 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=36475
http://www.ccsinfo.com/forum/viewtopic.php?t=37354
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Nov 19, 2010 11:26 am     Reply with quote

Hi All,

This thread makes me wonder if the topic is not applicable to a project I'm currently working on?

I've designed a Nixie tube clock that currently displays only UTC time and date (derived from a GPS module). The final step of the project is to allow 'local' time and date to be displayed instead based on a programmable UTC offset. The time calculation is trivial, but manipulating the date is another matter. I've written the conditional statements for this, and they are long and cumbersome, as well as almost impossible to test in any kind of a reasonable length of time! For example the day, month, and year may all need correction depending on when the adjustment is being made!

I'm wondering if a better way would be to convert the UTC time to an Elapsed Tick and then add/subtract the appropriate number of Ticks corresponding to the desired time offset, and then convert back to time/date to get local time/date?

Has anyone faced this issue before? Any suggestions for a compact, easily-testable solution?

Thanks,

John
barryg



Joined: 04 Dec 2006
Posts: 41

View user's profile Send private message

PostPosted: Fri Nov 19, 2010 2:31 pm     Reply with quote

Cool. When I think GPS, Nixie tubes are the first thing I think of Smile

I think your idea has merit. The conversions to and from ticks and dates are still messy, but at least people have been doing them for a long time, so the methods are proven, and then you can use them any way you like. I did an application that did logging and timestamping, and although I didn't have to do what you did...

Oh, wait, I did have to! Although this thing expected to be told what time it was, it was done in a way that it didn't have to know right away. The logs would store offsets from when it was turned on. Then when it got told the time, it would work back and figure out what all the other timestamps were. Subtracting the offsets from the reference time gave the true time. Then pushing it through the conversion made it look like it knew all along.

I worked out the conversions after finding this nifty little page on the Web: http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html

One optimization I did was to limit the range to like 100 years...I used 16 bits and subtracted a constant. Look for "2440587" and Jan 1 1970 if you want to do this.

I don't know if this will help the original poster, but it might. Dates are messy, however you approach it. Limited memory is a bummer when math's involved.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group