Skip to content

Commit

Permalink
Add tests for new modifiers and datetime func
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Jan 3, 2025
1 parent 7818e35 commit 33532a0
Showing 1 changed file with 145 additions and 1 deletion.
146 changes: 145 additions & 1 deletion testing/scalar-functions-datetime.test
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,148 @@ do_execsql_test unixepoch-at-start-of-time {

do_execsql_test unixepoch-at-millisecond-precision-input-produces-seconds-precision-output {
SELECT unixepoch('2022-01-27 12:59:28.052');
} {1643288368}
} {1643288368}

do_execsql_test date-with-modifier-start-of-day {
SELECT date('2023-05-18 15:30:45', 'start of day');
} {2023-05-18}

do_execsql_test date-with-modifier-start-of-month {
SELECT date('2023-05-18', 'start of month');
} {2023-05-01}

do_execsql_test date-with-modifier-start-of-year {
SELECT date('2023-05-18', 'start of year');
} {2023-01-01}

do_execsql_test date-with-modifier-add-months {
SELECT date('2023-05-18', '+2 months');
} {2023-07-18}

do_execsql_test date-with-modifier-subtract-months {
SELECT date('2023-05-18', '-3 months');
} {2023-02-18}

do_execsql_test date-with-modifier-add-years {
SELECT date('2023-05-18', '+1 year');
} {2024-05-18}

do_execsql_test date-with-modifier-subtract-years {
SELECT date('2023-05-18', '-2 years');
} {2021-05-18}

do_execsql_test date-with-modifier-weekday {
SELECT date('2023-05-18', 'weekday 0');
} {2023-05-21}

do_execsql_test date-with-multiple-modifiers {
SELECT date('2023-05-18', '+1 month', '-10 days', 'start of year');
} {2023-01-01}

do_execsql_test date-with-subsec {
SELECT date('2023-05-18 15:30:45.123', 'subsec');
} {2023-05-18}

do_execsql_test time-with-modifier-ceiling {
SELECT time('2023-05-18 15:30:45.987', 'ceiling');
} {15:30:46}

do_execsql_test time-with-modifier-floor {
SELECT time('2023-05-18 15:30:45.987', 'floor');
} {15:30:45}

do_execsql_test time-with-modifier-add-hours {
SELECT time('2023-05-18 15:30:45', '+5 hours');
} {20:30:45}

do_execsql_test time-with-modifier-subtract-hours {
SELECT time('2023-05-18 15:30:45', '-2 hours');
} {13:30:45}

do_execsql_test time-with-modifier-add-minutes {
SELECT time('2023-05-18 15:30:45', '+45 minutes');
} {16:15:45}

do_execsql_test time-with-modifier-subtract-seconds {
SELECT time('2023-05-18 15:30:45', '-50 seconds');
} {15:29:55}

do_execsql_test time-with-subsec {
SELECT time('2023-05-18 15:30:45.123', 'subsec');
} {15:30:45.123}

do_execsql_test date-with-modifier-add-months {
SELECT date('2023-01-31', '+1 month');
} {2023-03-03}

do_execsql_test date-with-modifier-subtract-months {
SELECT date('2023-03-31', '-1 month');
} {2023-03-03}

do_execsql_test date-with-modifier-add-months-large {
SELECT date('2023-01-31', '+13 months');
} {2024-03-02}

do_execsql_test date-with-modifier-subtract-months-large {
SELECT date('2023-01-31', '-13 months');
} {2021-12-31}

do_execsql_test date-with-modifier-february-leap-year {
SELECT date('2020-02-29', '+12 months');
} {2021-03-01}

do_execsql_test date-with-modifier-february-non-leap-year {
SELECT date('2019-02-28', '+12 months');
} {2020-02-28}

do_execsql_test date-with-modifier-invalid-date {
SELECT date('2023-03-31', '-1 month');
} {2023-03-03}

do_execsql_test time-with-multiple-modifiers {
SELECT time('2023-05-18 15:30:45', '+1 hours', '-20 minutes', '+15 seconds', 'subsec');
} {16:11:00.000}

do_execsql_test datetime-with-modifier-utc {
SELECT datetime('2023-05-18 15:30:45', 'utc');
} {{2023-05-18 15:30:45}}

do_execsql_test datetime-with-modifier-unixepoch {
SELECT datetime(1684401045, 'unixepoch');
} {{2023-05-18 09:10:45}}

do_execsql_test datetime-with-modifier-julianday {
SELECT datetime(2460082.5, 'julianday');
} {{2023-05-18 00:00:00}}

do_execsql_test datetime-with-weekday {
SELECT datetime('2023-05-18', 'weekday 3');
} {{2023-05-24 00:00:00}}

do_execsql_test datetime-with-auto {
SELECT datetime('2023-05-18', 'auto');
} {{2023-05-18 00:00:00}}

do_execsql_test unixepoch-subsec {
SELECT unixepoch('2023-05-18 15:30:45.123');
} {1684423845}

do_execsql_test unixepoch-invalid-date {
SELECT unixepoch('not-a-date');
} {{}}

do_execsql_test unixepoch-leap-second {
SELECT unixepoch('2023-06-30 23:59:60');
} {{}}

do_execsql_test unixepoch-negative-timestamp {
SELECT unixepoch('1969-12-31 23:59:59');
} {-1}

do_execsql_test unixepoch-large-date {
SELECT unixepoch('9999-12-31 23:59:59');
} {253402300799}

do_execsql_test datetime-with-timezone-change-negative {
SELECT datetime('2023-05-19 01:30:45+03:00', 'utc');
} {{2023-05-18 22:30:45}}

0 comments on commit 33532a0

Please sign in to comment.