Re: ctime double double check



aisling.cronin@xxxxxxxxx wrote:
On 9 Mar, 00:36, Keith Thompson <k...@xxxxxxx> wrote:
<snip>
<snip>
Any program that works with specific numeric time_t values is
non-portable, perhaps needlessly so. If you really need to work with
the specific representation I described above, you should ask in a
system-specific newsgroup, perhaps comp.unix.programmer.


I am trying to create a decoder...

I started in Perl and switched to C yesterday because of my issues
with converting the time. So I apologise for all my syntax errors. I
don't program everyday so I am slightly rusty...

The initial value is '00000109744ea6d6' I was told that I should split
the data up into 2bytes, the first 2bytes are spare, the next 6bytes
are the data, each 2bytes of data the last character gets counted up
(I have no idea why? Maybe someone could explain this to me?). The
rounded up 2bytes are then concated together and convert from hex to
decimal this is how I go the value 1144412677847. I have to take it in
good faith that this is correct... Although I was told yesterday that
the value 1144412677847 is in microseconds so that would explain why I
could not fit it into time_t.

Microseconds since when? Although the standard doesn't say
anything about sub-second divisions of time an implementation may
extend the struct tm structure and possibly alter the value of a
time_t variable to take milliseconds into consideration or not.
However I couldn't find anything in the standard that specifies
how the struct tm - time_t conversions should be done which means
it's up to the implementation, which also means that it is not
portable to use time_t between different applications.
If the number you are receiving is giving you the number of
milliseconds since a fixed time in the past it's up to you to
write a conversion tool or find something to convert it for you
but you should not rely on time_t.

How do people normally store / encode / decode unix/ posix machine
time? Has anyone seen this approach and can guide me?

If you are talking portable then store the numbers as ASCII text
like: "YYYYMMDDHHMMSS[ss] or YYYY-MM-DD HH:MM:SS[.ss]" or if
other format that suits you best. I think there is a standard for
storing date as a string of characters and it may look like in
the previous examples. The advantage of storing the time like
that is that it will also sort the time correctly even as a
string. To make it even more portable you could add a timezone
identifier somewhere.



--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

.



Relevant Pages

  • Re: Zero terminated strings
    ... How are you going to pass a 10MB string on the stack anyway? ... stacking that struct would be a trivial operation, ... Or did that famous Standard mung that equivalence too? ...
    (comp.lang.c)
  • Re: strict aliasing rules in ISO C, someone understands them ?
    ... > I try to understand strict aliasing rules that are in the C Standard. ... > Let's have two struct having different tag names, ... > struct s1 {int i;}; ... Accessing a member of the foreign structure type through the pointer ...
    (comp.lang.c)
  • Re: Yet another binary search tree library
    ... Some information in this wikipedia page is wrong. ... if there is undefined behavior or not (not counting ... As far as the Standard is concerned, ... kind of struct by means of member access (ie, ...
    (comp.lang.c)
  • Re: Why is C Standard Code Example Invalid?
    ... JK> that a declaration of the complete type of the union is ... the safest bet is to take the standard at it's ... struct t1; ... "E.MOS", which would suggest that the implicit dereference occurs, but ...
    (comp.std.c)
  • Re: Yet another binary search tree library
    ... alignment requirement as its first member (since there's no padding at ... As far as the Standard is concerned, ... uses an undefined construct the result is undefined behavior. ... a designator that is a different kind of struct. ...
    (comp.lang.c)