Skip to content

Instantly share code, notes, and snippets.

View spatialtime's full-sized avatar
🎨
Focusing

Matt Savage spatialtime

🎨
Focusing
View GitHub Profile
@spatialtime
spatialtime / iso8601_week.go
Created May 23, 2020 01:48
Demonstrates Golang formatting and parsing of ISO 8601 weeks
// This snippet demonstrates Golang formatting and parsing of ISO 8601 weeks.
import (
"errors"
"fmt"
"regexp"
"strconv"
"time"
)
@spatialtime
spatialtime / iso8601_ordinaldate.go
Last active May 23, 2020 01:58
Golang and ISO 8601 ordinal dates
// 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"
)
@spatialtime
spatialtime / parse_isoweek.plsql
Last active June 8, 2020 20:47
Parse an ISO 8601 week string (YYYY-Www or YYYY-Www-D) to an Oracle DATE value. Oracle's TO_*datetime functions do not support ISO year 'IYYY' Or ISO week 'IW' format model elements.
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]))?$';
@spatialtime
spatialtime / format_iso_dsinterval.plsql
Created June 8, 2020 23:12
A PL/SQL function that formats an Oracle INTERVAL DAY TO SECOND value to a conformant ISO 8601 duration string.
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
@spatialtime
spatialtime / format_iso_yminterval.plsql
Last active June 8, 2020 23:14
A PL/SQL function that formats an Oracle INTERVAL YEAR TO MONTH value to a conformant ISO 8601 string.
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';