How to automatically adjust datetimes to daylight saving time? #5916
-
Hi, I need to find a way to adjust incoming datetimes in HL7 messages with regard to daylight saving time. For example, I might know that the server time is one hour earlier than the time on client A that runs my channels on Mirth Connect. There is however also client B in a different country for which the server time is two hours later. I have made this configurable so that datetimes of client A always get one hour subtracted, and two hours are added to datetimes in client B. How do I go about fixing this? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Not a mirth question. Time zone management is a pain in the rear. You gotta sort out the calculations for your use case(s). However, I would normally not change timezones in the engine, rather call your db inserts/updates as per the timezone you know the client is in. Databases like postgres do that well. |
Beta Was this translation helpful? Give feedback.
-
A teammate recent handled a similar problem. Some key rules that we figured out during code reviews:
Roughly the process is:
|
Beta Was this translation helpful? Give feedback.
I don't think other database engines are as good at this as postgres. It takes a little more code to script it using the
java.time
classes mentioned by @jonbartels mainly because you'll be calling multiple java classes, which can be a little verbose, but it is not that difficult and is way more powerful if you need extra functionality not provided by a db engine.For example, one thing that I use it for is calculating the age of the patient at the date of service to place in a report header, and displaying it in months if < 2 years or years if >= 2 years (and it even easily handles edge cases involving leap years.)
This is what @pacmano1 's example would look like using
java.time
and hl7 …