-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Time Zone and Daylight Saving Time Customization for MDF Data #103
Conversation
# Conflicts: # mdflibrary/src/MdfHeader.cpp # mdflibrary/src/MdfHeader.h
Just for your information. I did removed all DST/TZ settings from the interface by design because it is bad idea to involve DST/TZ information in the MDF file. It's OK to have functions for DST/TZ settings but I recommend not to use them. It normally just ends up as a problem later on. There should be some issue in the MDFWriter::StartMeasurement(startTime) function. This function modifies the header start time. The reason is somewhat difficult to describe but the pre-trig time and the internal sample cache are involved. Inside, I use UTC for timestamps , so we need to find some condition when to set and not to set the header start time. A samples absolute time is header start time + sample relative time. Note that the relative time can be negative. |
Due to a lack of documentation, I would like to ask some questions: The definition of StartTime is |
MDF 4 definition of Start Time (same for File Header)Note there is currently no Time Flags defined. Proposal from me is that the Mdf4TimeStamp.h/cpp class exist but it is not public. Make an ITimeStamp class that defines the property interface and use this interface for getting/setting non-UTC absolute times. Keep the UTC time functions as is.
|
Alright, I will create an ITimestamp to set non-UTC times, but I have a question. When the flag is 0 or 2, the stored timestamp is in UTC and there are no issues. However, when the flag is 1, the stored local time must be adjusted by adding the timezone and daylight saving time offsets to display the current time in the Vector MDF Validator. Is this adjustment process done automatically by the library or does it need to be manually added by the user? If we allow the library to automatically make the adjustment, there might be issues with files generated over a long period experiencing time rollbacks due to daylight saving time changes. I would prefer that the user manually handle this to have more flexibility. |
It's up to you as the ITimestamp interface is new. If you have 4 properties (flag, time, dst_offset and tz_offset), The time (ns_1970) is dependent on the bit 0 flag. You can keep the current UTC functions but rename them NsSince1970->UtcSince1970 (or similar). The bit 1 flag defines if the offsets a valid or not. I suppose that these should be initialized in the constructor. In C++ it's a mess to getting these values however (Windows vs Linux). The .NET have a DateTime built into System, so the ITimestamp interface in MdfLibrary should use that DateTime structure. The MDF 3 always uses local time without DST offset only TZ offset. As before, try to use UTC only in your applications. It solves a lot of issues. Convert to local time format when presenting in an user interface. |
I suspect that you forget to add the new timestamp.h/cpp files to the cmake project file (mdflib/CMakeLists.txt). Just a minor fix. The MDF 3 specification is open source. The HD block includes both text and numeric times. It's a mess with DST and non-DST but always local time. Note that MDF 3 writing is seldom used. |
I should convert it into a draft before submitting it. The time part of the mdf3 section is not completed due to some uncertainties. I have already obtained the mdf3 document, and next, I will refer to the document for development. |
Just a hint. There are 2 examples at the end of the page. This could be the input for a unit test that test the HD3 times. |
The development of the feature has been completed, and the unit tests have passed on my local machine. However, since I'm not very familiar with C++/CLI, I've tried various methods but still can't resolve the compilation errors in the CI unit tests. I might need some help with this. |
I made a fast analyze of the GitHub Action logs and it is the MdfLibrary (.NET assembly) linking by CMAKE that complains. The linker error messages are not the most user friendly but it is missing some code. I suspect that the MdfLibrary::CMakeLists.txt is missing some new files. Can't find the MdfUtfTimestamp and MdfLocalTimestamp source files in GIT. It could be some files missing in the C++ MdfLib as well.
The .NET CMAKE build is only made by one GitHub Action. I have not figure out how to build a Visual Studio Solution file with GitHub Action but I save that for a rainy day. |
That makes sense then. My Visual Studio probably didn't use CMake but directly used the built-in vcxproj for building. I'll give it another try. |
@simonkimi |
I needed to customize the time zone and daylight saving time for MDF data, but these features are currently not available. Additionally, the time handling between MDF3 and MDF4 is different—MDF4 defaults to UTC time, while MDF3 defaults to local time. Considering that some users might already be using these functions, I have added three new functions:
SetStartTimeLocal
,SetStartTimeUtc
, andSetStartTimeWithZone
.Please note that since I do not have access to the official MDF file format documentation (it appears to be a paid resource), the data was inferred using the Vector MDF Validator. There might be some issues as a result.