Convert date to international format (UTC). Template for XSLT versions from 1.0
It was required to translate the date in xml files from Moscow time to international. Initially, the problem was solved by inserting Java squeak, but it had to be done using only the built-in features of XSLT 1.0.
I immediately warn commenters, the XSLT 2.0 version, where there is a Date data type, is not good, it needs to be implemented in 1.0.
Download the example, template, result and parser here.
So, the steps to solve the problem:
Subtasks:
Original date template:
DD.MM.YYYY hh: mm: ss
You can adjust XSL to your format without any problems, just change the cutting sequence and specify the delimiters.
UTC date format:
YYYY-MM-DD hh: mm: ss
Corrected even easier when collecting the final string.
If other time zone offsets are required, simply correct them in the MoscowOffsetTime function.
Using the template:
Actually the template code itself:
I immediately warn commenters, the XSLT 2.0 version, where there is a Date data type, is not good, it needs to be implemented in 1.0.
Download the example, template, result and parser here.
So, the steps to solve the problem:
- Splitting the original date in our format into components.
- Determining the time zone offset relative to UTC, taking into account the transition to winter / summer time, for Moscow in the summer the offset is -4, in winter -3. Daylight saving time changes at two in the morning on the last Sunday of March, and switches to winter time at three in the morning on the last Sunday of October.
- Translation of all parts of the date in UTC time
- Date collection in UTC format.
Subtasks:
- Day of the week search, Zeller’s formula is used
- Search for the number of days in a month
- Leap year test
Original date template:
DD.MM.YYYY hh: mm: ss
You can adjust XSL to your format without any problems, just change the cutting sequence and specify the delimiters.
UTC date format:
YYYY-MM-DD hh: mm: ss
Corrected even easier when collecting the final string.
If other time zone offsets are required, simply correct them in the MoscowOffsetTime function.
Using the template:
* This source code was highlighted with Source Code Highlighter.
Actually the template code itself:
--::
0
12
31
30
29
28
30
-4
-3
-4
-4
-3
-4
-3
-3
-4
-3
5
6
* This source code was highlighted with Source Code Highlighter.