XSLT convert UTC to tz timezone - xslt

I have the following variable:
<xsl:variable name="time">
<xsl:value-of select="'2020-12-26T17:33:11Z'"/>
</xsl:variable>
<xsl:variable name="timeZone">
<xsl:value-of select="'America/Los_Angeles'" />
</xsl:variable>
The variable time is in UTC and I would like to convert it to the local timezone. I am using the following but that is not working:
<xsl:value-of select="adjust-dateTime-to-timezone($time), xs:dayTimeDuration($timeZone))"/>
My expected output is: 2020-12-26T09:33:11Z

Nearly all the date/time/timezone functionality in XSLT/XPath is based on absolute numeric timezone offset such as -05:00, not on civil timezones such as CET or America/Los_Angeles. The one exception is format-dateTime(), which is designed to format data for human consumption. The fifth argument to format-dateTime() is "place": XPath 3.1 says:
If the $place argument is supplied in the form of an IANA timezone
name that is recognized by the implementation, then the date or time
being formatted is adjusted to the timezone offset applicable in that
timezone. For example, if the xs:dateTime value 2010-02-15T12:00:00Z
is formatted with the $place argument set to America/New_York, then
the output will be as if the value 2010-02-15T07:00:00-05:00 had been
supplied. This adjustment takes daylight savings time into account
where possible; if the date in question falls during daylight savings
time in New York, then it is adjusted to timezone offset -PT4H rather
than -PT5H. Adjustment using daylight savings time is only possible
where the value includes a date, and where the date is within the
range covered by the timezone database.
Note that this is new in XPath 3.x; the 2.0 specification only allowed a country code to be used, and was much vaguer about what it meant.

Related

Prestosql/Amazon Athena: Time Zone Change

I need to change a UTC timestamp to 'US/Eastern' timestamp without changing the date and time - essentially update only the timezone information and later convert that to a different timezone.
For example (what I need):
'2021-06-09 19:00:36.000000' UTC --> '2021-06-09 19:00:36.000000' US/Eastern
Then I need to convert that to 'America/New_York'.
'2021-06-09 19:00:36.000000' US/Eastern --> '2021-06-09 16:00:36.000000' America/Los Angeles
When I try the query below, it's not giving me the correct results, since it is converting from UTC to America/Los Angeles. When it should be US/Eastern to America/Los Angeles.
SELECT id
, date_utc
, CAST(date_utc AT TIME ZONE 'America/Los Angeles') AS date_la
FROM call_records
I'm not sure if this will work for Athena, as it's based on a very old version of Presto/Trino.
In recent versions of Trino (formerly known as PrestoSQL), you can do this:
Cast the timestamp with time zone to timestamp to remove the timezone part.
Then, use with_timezone to reinterpret the resulting timestamp in US/Eastern.
Finally, use AT TIME ZONE to change the time zone of the resulting timestamp with time zone while preserving the instant.
Take a look at the example below:
trino:tiny> WITH t(ts) AS (VALUES TIMESTAMP '2021-06-09 19:00:36.000000 UTC')
-> SELECT with_timezone(cast(ts as timestamp(6)), 'US/Eastern') AT TIME ZONE 'America/Los_Angeles'
-> FROM t;
_col0
------------------------------------------------
2021-06-09 16:00:36.000000 America/Los_Angeles
(1 row)

How parse datetime format from datebase?

The database (SQLite) has a field of type REAL with the values of the form (42153.659595).
How to translate this value in the form "dd.MM.yy HH:mm:ss" if 42153.659595 = 29.05.2015 15:49:49 ?
You can be explicit about what calendar system you require: http://www.sqlite.org/lang_datefunc.html
SELECT julianday('now') - julianday('1776-07-04');
In principle just don't "parse" (you mean: interpret raw representation). Use Sqlite API/builtin SQL functions to do it for you
In the interest of information:
The date and time functions use a subset of IS0-8601 date and time formats.
The datetime() function returns "YYYY-MM-DD HH:MM:SS". The julianday() function returns the Julian day - the number of days since noon in Greenwich on November 24, 4714 B.C. (Proleptic Gregorian calendar)
The date() function returns the date in this format: YYYY-MM-DD. The time() function returns the time as HH:MM:SS.
The correct value is achieved using the API/builtin SQL functions (42153.659595 - value from database):
SELECT datetime(julianday(42153.659595, 'localtime') + 2415018.29167) AS DT;
Output:
DT |
2015-05-29 15:49:49|
Constant 2415018.29167 was selected manually and query:
SELECT datetime (2415018.29167);
returns the current Greenwich Mean Time.
I work with a third-party application and documentation on the database is missing. Perhaps this strange decision, but it works. Thank you all for answers.

Difference between dateformat() and createODBCDate() in ColdFusion

What is the difference between dateformat() and createODBCDate() in ColdFusion? Are these two functions the same or not? When do I need to use DateFormat() and when do I need to use createODBCDate()?
dateFormat() accepts a date and a format 'mask' and returns a string of the date, in the format passed.
For example, consider the following code:
mydate = dateFormat( now(), 'yyyy-mm-dd' );
Assuming the date is July 15, 2014 (which it was when I wrote this) the value of the variable named 'mydate' would be '2014-07-15' (without the quotes). So, you need to pass a date to the function.
createODBCDate() creates an actual date from the values passed - it does not format the date, it merely creates a date 'object'
dateFormat() is typically used to display a date in a user friendly manner. Try running this writeDump( now() ) to see what the default display looks like.
createODBCDate() is typically used when you need to pass a date to a SQL query. However, if you use cfqueryparam with a cf_sql_type that accepts a date, ColdFusion will handle converting the value (assuming it is a valid date) to a date that the database accepts and you do not need to use createODBCdate()
In 10+ years of doing ColdFusion, I have never used createODBCDate()

XSLT axis for siblings across trees?

I am using XSLT to generate some webpages and I need to create links for the next and previous day. The structure is roughly as follows:
year
month
day
day
...
month
day *
day
...
...
...
Tried using the preceding-sibling and following-sibling axis, but then discovered they of course won't work for the first and last day of a month. For example preceding-sibling would return nothing for the day marked with *.
How can I get the previous and next day for a given day, across the year and month "barriers", using XSLT 1.0?
The axis operators you are looking for in this case are preceding and following, which gets the preceding or following node regardless of the level in the hierarchy.
<xsl:copy-of select="following::day[1]" />
<xsl:copy-of select="preceding::day[1]" />

parsing date and time

Currently In my source file, i am getting date and time values like below.
2010-07-06T19:06:47
i want to put date in one variable and time in another one. Please let me know how to do this.
Assuming the combined date/time value is in variable $date-time...
<xsl:variable name="date" select="substring-before($date-time, 'T')"/>
<xsl:variable name="time" select="substring-after($date-time, 'T')"/>
The quickest and easiest way to do this would be to split/explode the variable into 2 pieces with the date in one and the time in the other.
Date Parsing means converting String into Date. Same Simple DateFormat codes are used to parsing date.
For example,
DateFormat formatter = new SimpleDateFormat("MM/dd/yy");<br/>
Date date = (Date)formatter.parse("07/16/87");<br/>
formatter = new SimpleDateFormat("dd-MMM-yy");<br/>
date = (Date)formatter.parse("16-Jul-87");<br/>
Source : Tutorial Data - Date and Time