Last active
October 11, 2016 04:38
-
-
Save WaxCylinderRevival/f71d6b6afbd88b642cb862574ad4adb3 to your computer and use it in GitHub Desktop.
Function to convert certain ISO 8601-compliant formats [date(yyyy-mm-dd) or dateTime] to epoch/Unix time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module namespace epoch = "https://gist.github.com/WaxCylinderRevival/ns/xquery/date-to-epoch-time"; | |
declare function epoch:date-to-epoch-time | |
( $dateString as xs:string? ) as xs:decimal? { | |
if (empty($dateString)) | |
then () | |
else | |
if (matches($dateString, '^\d{4}-\d{2}-\d{2}$')) | |
then (xs:dateTime(xs:date($dateString)) - xs:dateTime("1970-01-01T00:00:00-00:00")) div xs:dayTimeDuration('PT1S') | |
else | |
(xs:dateTime($dateString) - xs:dateTime("1970-01-01T00:00:00-00:00")) div xs:dayTimeDuration('PT1S') | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment