[opensuse-programming] C# DateTime and Linux gettimeofday
The Linux/UNIX gettimeofday() function reports the time in the current Epoch. That Epoch is defined as starting "00:00:00 UTC, January 1, 1970" C# provides a DateTime interface with a similar concept of time in the current Epoch. Just to make life interesting, C# defines the Epoch as being "12:00:00, January 1, 0001". (Note the mysterious absence of UTC in that start...) This is, of course, just some offset. My problem is that I am trying to find out if the offset is some agreed international standard. I must be looking in the wrong place. I see lots of C# code to fiddle with this. But what about us crazy C programmers on Linux? For example, System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); tells the time in the C# Epoch at the start of the Linux/UNIX epoch. I guess I could run this once and save the result as an offset. But I would be a bit happier if there was some agreed value for this so I do not chance getting a bad value from some buggy C# implementation. I'm a suspicious type of guy sometimes. This question has arisen because we I am integrating some fancy Danish reflection measurement device into our Linux apps. The data provided by these devices is timestamped with UTC time - encoded with the C# DateTime functions, e.g., 5246315282908540247, which must have been around 1400 UTC today. Has anyone made an interface between the Linux Epoch and the C# Epoch? It seems to me that for this to work, all involved parties must agree on the elapsed time between C# Epoch start and some more recent Epoch that has greater agreement on how elapsed time is calculated. Yours sincerely, Roger Oberholtzer OPQ Systems / Ramböll RST Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 roger.oberholtzer@ramboll.se ________________________________________ Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden www.rambollrst.se -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
On Mon, 2012-01-23 at 16:45 +0100, Roger Oberholtzer wrote:
The Linux/UNIX gettimeofday() function reports the time in the current Epoch. That Epoch is defined as starting "00:00:00 UTC, January 1, 1970"
Yep.
C# provides a DateTime interface with a similar concept of time in the current Epoch. Just to make life interesting, C# defines the Epoch as being "12:00:00, January 1, 0001". (Note the mysterious absence of UTC in that start...)
Yep.
This is, of course, just some offset. My problem is that I am trying to find out if the offset is some agreed international standard. I must be looking in the wrong place. I see lots of C# code to fiddle with this. But what about us crazy C programmers on Linux?
Different platforms use different epochs. Various RDBMSs for example use different epochs to persist dates & times.
For example, System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); tells the time in the C# Epoch at the start of the Linux/UNIX epoch. I guess I could run this once and save the result as an offset. But I would be a bit happier if there was some agreed value for this so I do not chance getting a bad value from some buggy C# implementation. I'm a suspicious type of guy sometimes.
Don't use offsets like this. If you need to pass date values between heterogenous systems it is both safer and easier to 'export' the date to a standard string representation and then parse that standard string representation 'on the other side' [like ISO8601 - every platform has a way to process those datetime values]. Tiemstamps are evil; I avoid storing them.
This question has arisen because we I am integrating some fancy Danish reflection measurement device into our Linux apps. The data provided by these devices is timestamped with UTC time - encoded with the C# DateTime functions, e.g., 5246315282908540247, which must have been around 1400 UTC today.
Ugh. That sucks.
Has anyone made an interface between the Linux Epoch and the C# Epoch?
No. It would be interesting to see what happens as you cross time zones or enter or leave day light savings time periods.
It seems to me that for this to work, all involved parties must agree on the elapsed time between C# Epoch start and some more recent Epoch that has greater agreement on how elapsed time is calculated.
Or, better, stop storing timestamps. You know what time it is, store that, not some integer. -- System & Network Administrator [ LPI & NCLA ] <http://www.whitemiceconsulting.com> OpenGroupware Developer <http://www.opengroupware.us> Adam Tauno Williams
On Mon, 2012-01-23 at 11:14 -0500, Adam Tauno Williams wrote:
Or, better, stop storing timestamps. You know what time it is, store that, not some integer.
This would be my approach. But the Danish device took a different approach that I have to live with. I am also trying to get them to tell the resolution of the time. Yours sincerely, Roger Oberholtzer OPQ Systems / Ramböll RST Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 roger.oberholtzer@ramboll.se ________________________________________ Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden www.rambollrst.se -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
Roger Oberholtzer wrote:
On Mon, 2012-01-23 at 11:14 -0500, Adam Tauno Williams wrote:
Or, better, stop storing timestamps. You know what time it is, store that, not some integer.
This would be my approach. But the Danish device took a different approach that I have to live with.
I think I'm getting it - you get a timestamp in <units> (seconds?) relative to an Epoch beginning at X. It can't be too difficult adding or subtracting the difference to another Epoch beginning at Y ? /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
Roger Oberholtzer wrote:
The Linux/UNIX gettimeofday() function reports the time in the current Epoch. That Epoch is defined as starting "00:00:00 UTC, January 1, 1970"
C# provides a DateTime interface with a similar concept of time in the current Epoch. Just to make life interesting, C# defines the Epoch as being "12:00:00, January 1, 0001". (Note the mysterious absence of UTC in that start...)
This is, of course, just some offset. My problem is that I am trying to find out if the offset is some agreed international standard.
I don't think it is - it is operating-system dependent. http://en.wikipedia.org/wiki/System_time#Retrieving_system_time
This question has arisen because we I am integrating some fancy Danish reflection measurement device into our Linux apps. The data provided by these devices is timestamped with UTC time - encoded with the C# DateTime functions, e.g., 5246315282908540247, which must have been around 1400 UTC today.
Just wondering - why not just stick to UTC timestamps, and ignore the Epoch? /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
On Mon, 2012-01-23 at 17:23 +0100, Per Jessen wrote:
Roger Oberholtzer wrote:
The Linux/UNIX gettimeofday() function reports the time in the current Epoch. That Epoch is defined as starting "00:00:00 UTC, January 1, 1970"
C# provides a DateTime interface with a similar concept of time in the current Epoch. Just to make life interesting, C# defines the Epoch as being "12:00:00, January 1, 0001". (Note the mysterious absence of UTC in that start...)
This is, of course, just some offset. My problem is that I am trying to find out if the offset is some agreed international standard.
I don't think it is - it is operating-system dependent.
http://en.wikipedia.org/wiki/System_time#Retrieving_system_time
This is what I fear.
This question has arisen because we I am integrating some fancy Danish reflection measurement device into our Linux apps. The data provided by these devices is timestamped with UTC time - encoded with the C# DateTime functions, e.g., 5246315282908540247, which must have been around 1400 UTC today.
Just wondering - why not just stick to UTC timestamps, and ignore the Epoch?
I could pass the response to the Danes who made the device. They are already wondering why I use Linux. That tells a bit... Yours sincerely, Roger Oberholtzer OPQ Systems / Ramböll RST Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 roger.oberholtzer@ramboll.se ________________________________________ Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden www.rambollrst.se -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
Roger Oberholtzer wrote:
On Mon, 2012-01-23 at 17:23 +0100, Per Jessen wrote:
Roger Oberholtzer wrote:
The Linux/UNIX gettimeofday() function reports the time in the current Epoch. That Epoch is defined as starting "00:00:00 UTC, January 1, 1970"
C# provides a DateTime interface with a similar concept of time in the current Epoch. Just to make life interesting, C# defines the Epoch as being "12:00:00, January 1, 0001". (Note the mysterious absence of UTC in that start...)
This is, of course, just some offset. My problem is that I am trying to find out if the offset is some agreed international standard.
I don't think it is - it is operating-system dependent.
http://en.wikipedia.org/wiki/System_time#Retrieving_system_time
This is what I fear.
This question has arisen because we I am integrating some fancy Danish reflection measurement device into our Linux apps. The data provided by these devices is timestamped with UTC time - encoded with the C# DateTime functions, e.g., 5246315282908540247, which must have been around 1400 UTC today.
Just wondering - why not just stick to UTC timestamps, and ignore the Epoch?
I could pass the response to the Danes who made the device. They are already wondering why I use Linux. That tells a bit...
Sure, crazy people all around :-) But I thought you said you get UTC time from those devices? /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
On Mon, 2012-01-23 at 18:28 +0100, Per Jessen wrote:
Sure, crazy people all around :-) But I thought you said you get UTC time from those devices?
It is. It is just that it is encoded using the C# DateTime() mechanism: ToBinary().ToString() which provides values like 5246315282908540247 (in a text string) The C# DateTime, it seems, has as the start of the Epoch "12:00:00, January 1, 0001". If they had printed some ISO date format, I would have been happier. I think it is an odd way to record a UTC time stamp that is to be used to connect their data to other devices. Danes... I have discovered that the last 7 values are the fractional part of a second. So, the value in seconds is: 524631528290.8540247 Since year 1. I am going to check if that is reasonable. Both Mono http://docs.go-mono.com/index.aspx?link=T:System.DateTime and MS http://msdn.microsoft.com/en-us/library/system.datetime.aspx define the function the same. Perhaps I should peek at the Mono implementation. Yours sincerely, Roger Oberholtzer OPQ Systems / Ramböll RST Office: Int +46 10-615 60 20 Mobile: Int +46 70-815 1696 roger.oberholtzer@ramboll.se ________________________________________ Ramböll Sverige AB Krukmakargatan 21 P.O. Box 17009 SE-104 62 Stockholm, Sweden www.rambollrst.se -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
Roger Oberholtzer wrote:
On Mon, 2012-01-23 at 18:28 +0100, Per Jessen wrote:
Sure, crazy people all around :-) But I thought you said you get UTC time from those devices?
It is. It is just that it is encoded using the C# DateTime() mechanism:
ToBinary().ToString()
which provides values like 5246315282908540247 (in a text string)
Sounds completely stupid. You would think there was a better, more inter-operable way.
that is to be used to connect their data to other devices. Danes...
:-) /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-programming+owner@opensuse.org
participants (3)
-
Adam Tauno Williams
-
Per Jessen
-
Roger Oberholtzer