CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
date5.test87 linesDownload Raw Back to test
1# 2024-08-192#3# The author disclaims copyright to this source code.  In place of4# 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/eaa0a09786c6368b13#14# Apparently SQLite has been miscomputing leap-year dates before15# the year 0400.16#17 18set testdir [file dirname $argv0]19source $testdir/tester.tcl20 21# Skip this whole file if date and time functions are omitted22# at compile-time23#24ifcapable {!datetime} {25  finish_test26  return27}28 29# Data sources:30#   1-10  https://ssd.jpl.nasa.gov/tools/jdc/#/cd31#   11    Jean Meeus, Astronomical Algorithms, ISBN 0-943396-61-1, p.5932#   12    https://en.wikipedia.org/wiki/Julian_day33#   34# ID YEAR MONTH DAY JD35set date5data {36   1 2024     2  29 2460369.537   2 2024     3   1 2460370.538   3 2023     2  28 2460003.539   4 2023     3   1 2460004.540   5 2000     2  29 2451603.541   6 2000     3   1 2451604.542   7 1900     2  28 2415078.543   8 1900     3   1 2415079.544   9 1712     2  29 2346413.545  10 1712     3   1 2346414.546  11 1977     4  26 2443259.547  12 2013     1   1 2456293.548}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  } $date55  do_execsql_test date5-cal/$date {56    SELECT julianday($::date);57  } $jd58  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    } $date265    do_execsql_test date5-cal/$date2 {66      SELECT julianday($::date2);67    } $jd268  }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    } $date280    do_execsql_test date5-cal/$date2 {81      SELECT julianday($::date2);82    } $jd283  }84}85 86finish_test87