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
CREATE OR REPLACE FUNCTION format_iso_yminterval(interval_in INTERVAL YEAR TO MONTH) RETURN VARCHAR2 | |
IS | |
iso_out VARCHAR2(14) := 'P'; | |
year NUMBER; | |
month NUMBER; | |
BEGIN | |
year := EXTRACT(YEAR FROM interval_in); | |
IF year <> 0 THEN | |
iso_out := iso_out || year || 'Y'; |
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
CREATE OR REPLACE FUNCTION format_iso_dsinterval(interval_in INTERVAL DAY TO SECOND) RETURN VARCHAR2 | |
IS | |
--max value ever would be 'P999999999DT59H59M59.999999999S', a 31-char string | |
l_iso VARCHAR2(31) := 'P'; | |
l_day NUMBER; | |
l_hour NUMBER; | |
l_minute NUMBER; | |
l_second NUMBER; | |
BEGIN |
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
CREATE OR REPLACE FUNCTION parse_isoweek(isostring_in STRING) RETURN DATE | |
IS | |
l_year_start DATE; | |
l_year VARCHAR2(4); | |
l_week VARCHAR2(2); | |
l_day VARCHAR2(1); | |
l_date DATE; | |
--c_pattern allows for 'YYYY-Www' and 'YYYY-Www-d' formats. | |
c_pattern CONSTANT VARCHAR2(33) := '^(\d{4})-W([0-5]\d)((-)([1-7]))?$'; |
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
// This snippet demonstrates Golang formatting and parsing of | |
// ISO 8601 ordinal dates (4-digit year + "-" + ordinal day). | |
// Note: an ordinal day in this context is the nth day of | |
// the year, with Jan 1 being ordinal day 1 and Dec 31 | |
// of non-leap year (a "common year") being day 365. | |
import ( | |
"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
// This snippet demonstrates Golang formatting and parsing of ISO 8601 weeks. | |
import ( | |
"errors" | |
"fmt" | |
"regexp" | |
"strconv" | |
"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
// This snippet demonstrates Golang formatting and parsing of ISO 8601 durations. | |
// A little work is required to navigate between Golang's | |
// duration syntax and ISO 8601 duration syntax. | |
import ( | |
"errors" | |
"fmt" | |
"regexp" | |
"strings" | |
"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
//------------------------------------------------------------------------------ | |
// Constants | |
//------------------------------------------------------------------------------ | |
const MIN_YEAR =1; | |
const MAX_YEAR = 9999; | |
const MIN_MONTH = 1; | |
const MAX_MONTH = 12; | |
const MIN_DAY = 1; | |
const MIN_HOUR = 0; | |
const MAX_HOUR = 24; |
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
//------------------------------------------------------------------------------ | |
// Constants | |
//------------------------------------------------------------------------------ | |
const MIN_YEAR =1; | |
const MAX_YEAR = 9999; | |
const MIN_MONTH = 1; | |
const MAX_MONTH = 12; | |
const MIN_DAY = 1; | |
const MIN_HOUR = 0; | |
const MAX_HOUR = 24; |
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
/* | |
* dateFromISODatetime creates a JavaScript date from a string that adheres to | |
* ECMAScript's specified syntax: | |
* Zulu/UTC time: | |
* YYYY-MM-DDTHH:mm:ss.sssZ | |
* Specified time zone offset: | |
* YYYY-MM-DDTHH:mm:ss.sss±HH:mm | |
* Local time (no time zone specification): | |
* YYYY-MM-DDTHH:mm:ss.sss | |
*/ |
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
// Passing a string to new Date() is cross-implementation-safe only if the | |
// format of the string conforms to ECMAScript's specified format. | |
// From the specification (https://tc39.es/ecma262/#sec-date.parse): | |
// " If the String does not conform to that format the function may fall | |
// back to any implementation-specific heuristics or implementation-specific date formats. " | |
// As such, we are good to go here with passing it a correct ISO 8601 date/time string. | |
let d = new Date("2020-04-02T13:00:00.000Z") | |
// The beauty of a fixed-width ISO 8601 output string. |
NewerOlder