interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / date5.test

86 lines · 2265 bytes Raw Blame History
1# 2024-08-19
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# https://sqlite.org/forum/forumpost/eaa0a09786c6368b
13#
14# Apparently SQLite has been miscomputing leap-year dates before
15# the year 0400.
16#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21# Skip this whole file if date and time functions are omitted
22# at compile-time
23#
24ifcapable {!datetime} {
25 finish_test
26 return
27}
28
29# Data sources:
30# 1-10 https://ssd.jpl.nasa.gov/tools/jdc/#/cd
31# 11 Jean Meeus, Astronomical Algorithms, ISBN 0-943396-61-1, p.59
32# 12 https://en.wikipedia.org/wiki/Julian_day
33#
34# ID YEAR MONTH DAY JD
35set date5data {
36 1 2024 2 29 2460369.5
37 2 2024 3 1 2460370.5
38 3 2023 2 28 2460003.5
39 4 2023 3 1 2460004.5
40 5 2000 2 29 2451603.5
41 6 2000 3 1 2451604.5
42 7 1900 2 28 2415078.5
43 8 1900 3 1 2415079.5
44 9 1712 2 29 2346413.5
45 10 1712 3 1 2346414.5
46 11 1977 4 26 2443259.5
47 12 2013 1 1 2456293.5
48}
49
50foreach {id y m d jd} $date5data {
51 set date [format %04d-%02d-%02d $y $m $d]
52 do_execsql_test date5-jd$jd {
53 SELECT date($::jd);
54 } $date
55 do_execsql_test date5-cal/$date {
56 SELECT julianday($::date);
57 } $jd
58 for {set i 1} {$y+400*$i<=9999} {incr i} {
59 set y2 [expr {$y+400*$i}]
60 set date2 [format %04d-%02d-%02d $y2 $m $d]
61 set jd2 [expr {$jd+146097*$i}]
62 do_execsql_test date5-jd$jd2 {
63 SELECT date($::jd2);
64 } $date2
65 do_execsql_test date5-cal/$date2 {
66 SELECT julianday($::date2);
67 } $jd2
68 }
69 for {set i 1} {$y-400*$i>=-4712} {incr i} {
70 set y2 [expr {$y-400*$i}]
71 if {$y2<0} {
72 set date2 [format -%04d-%02d-%02d [expr {-$y2}] $m $d]
73 } else {
74 set date2 [format %04d-%02d-%02d $y2 $m $d]
75 }
76 set jd2 [expr {$jd-146097*$i}]
77 do_execsql_test date5-jd$jd2 {
78 SELECT date($::jd2);
79 } $date2
80 do_execsql_test date5-cal/$date2 {
81 SELECT julianday($::date2);
82 } $jd2
83 }
84}
85
86finish_test