I have CSV data files with timestamped records that are in local time. Unfortunately the data files cover the period where daylight saving time changes (Nov 3rd 2013) so the time component of the timestamps for the records go: 12:45, 1:00, 1:15, 1:30, 1:45, 1:00, 1:15, 1:30, 1:45, 2:00
. I want to be able to convert and store the values in the database as UTC.
Unfortunately the standard DateTime.Parse()
function of .NET will parse as this (all November 3rd 2013):
| Time String | Parsed Local Time | In DST | Parsed Local Time to UTC
| 12:45 am | 12:45 am | Yes | 4:45 am
| 12:59:59 am | 12:59:59 am | Yes | 4:59:59 am
| 01:00 am | 1:00 am | No | 6:00 am
| 01:15 am | 1:15 am | No | 6:15 am
So it never sees the 1:00-1:59:59 am
range as being in DST and my parsed timestamps in UTC jumps an hour.
Is there a library or class out there that will allow me to parse the timestamps and take into account the change in DST? Like some instantiatable class that will remember the stream of timestamps it's already received and adjust the parsed timestamp accordingly?
Assumptions about the data that can be made while parsing:
- I have the start time of file (timestamp of the first record) in the header section of the file in both local and UTC.
- The records are in order by timestamp
- All local times are in Eastern Standard
- The data could also go the other way: from out of DST into it
- The records contain a full timestamp in the format:
yyyy/mm/dd HH:mm:ss
(2013/11/03 00:45:00
)
Note: While my software is in C#, I did not tag C#/.NET specifically as I figured I could use any language's implementation of a solution and recode if necessary.