Reputation: 3
I have an API, which reads the time format from TZ variable using getenv
EST+5EDT,M3.2.0/2,M11.1.0/2
Here M3.2.0/2 is the DST begin date and time M11.1.0/2 is the DST end date and time
Note: |This format specifies day d of week w of month m. The day must be between 0(Sunday) and 6 , week must be between 1 and 5; week1 is the first week in which day d occurs and week 5 specifies the last d in the month. The month is between 1 and 12.|
I want to print the start date as Mar/08 Sun @2.00pm
and end date as Nov/01 Sun @2.00pm
If in my own code, I can parse the TZ and get the start(M3.2.0/2) and end(M11.1.0/2) dates. But I need to get the correct date format.
Is there any way to do it with library functions or I need to create my own code.
Upvotes: 0
Views: 155
Reputation: 12708
The actual implementation of timezones in the majority of implementations is based on Timezone Database, which is an opensource reference library and database of timezones. If you study that library and database, you'll see that the actual today implementation of that library doesn't use anymore the start date times and end date times (as was used by previous libraries, leading to failing and unprecise conversions), as it does cope with local implementations in which Daylight Savings Time is not applied for some years or changes are applied by governments duiring some periods.
If you use the approach you post, you will incurr in errors when using a fixed rule when you are dealing with timestamps in periods in which Daylight Savings were not applied or applied differently than normal.
For a reference, consult IANA tz database which includes a completely updated database (probably already used in your system) and the reference code to access it (probably also already included in your system)
Upvotes: 2