From 459fa037d7149b173de0dd516968a8fed22b89e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20A=2E=20Holm?= Date: Tue, 26 Sep 2023 17:22:52 +0200 Subject: [PATCH] datefmt: Define 1 year as 365.2425 days instead of 365.25 According to sqlite3, it's much more accurate. For example: SQLite version 3.43.1 2023-09-11 12:01:27 sqlite> select datetime(julianday('2023-09-26')-6000*365.25); -3977-08-12 00:00:00 sqlite> select datetime(julianday('2023-09-26')-6000*365.2425); -3977-09-26 00:00:00 sqlite> select datetime(julianday('2023-09-26')+7000*365.2425); 9023-09-26 12:00:00 sqlite> select datetime(julianday('2023-09-26')+7000*365.25); 9023-11-18 00:00:00 I chose 365.25 days back in the day because it aligns with the astronomical year, offers greater consistency with fewer fractions, and is a widely accepted standard in scientific contexts. However, for improved accuracy, it's better to use the Gregorian year rather than the Julian year. Here's the whole experiment session, compressed with gzip+base64: H4sIAOzJ EmUCA93X 7WrbMBQG 4P++ChEG bRfsHR19 qzAYI4NB NxhjF+At 2uqROFns Dnr3k91k sdTkR2UP yiAQMPjJ 66PjI+UF aX6tqtax 7POnG/9N frtdU21q wgrOCkoQ kOVgckoJ RQvUosoW det2ZFbc utV2Rr5v duSuKX84 clvVbVNk bzd17b61 bknaDSlJ uyvrpnJ1 S6o6X7v1 ZndPlmVb fi0bV2Rf GuelzdbV 5N37m8XH Nx8Ws+6+ neuv+SAl 2XaRmrYj jjc+xH5N GrfyP0Yu f96tqrJe lveXF4fM KC+u8sF1 ao7Xr64z JgWKAkZL 5BXxVIHi OqMAiaA+ AxpTGKNQ IuUGKUuy 1Wkbe5sL 5Gg0R5lk y9M2622q tORcSWaS bDxtq87W TCjURqBS KTacXcAO VxqMooY9 on37ubZa u7M/4RsA Xj5gV522 f3kMAbD9 J0UcgH9j p4MYgIe+ ExOAPCRl PzGSSBaR 6vjYMr2O oQnjYw5N jExje/ZZ 5OSR6RtS qbF9xINW 35M6R5VO moB88u0y TMT2iSim J5Jx5dgE lRMxikd0 zCsTojAB ihEKMMn8 GawSHM8X E4hTpkQW mgD7QUk9 qC3yEeZQ pJA+1P5R Sh42EgA9 lJPbfrCl oCJGcZ8U 0bLUp5cx etjNqLQc LNcJ71FY 0n4gH5Om 1XSIygil 3ApmQYxC eYD6hRIW meU4Cg1M 1XUU+qzq +T39ZOvE YxQneKFE jLIJkg5M ajwaBqXa d3/C0SNC w4biwgIf NaJ6FAYo tdT/o9T/ 53SehyIH Lj3XiX55 UsXh3tl1 ay+m753z eO/k4/fO eXy+UeOP sPP4IKYn yGki88mA HguoCDAT VEoFPdKL lOZUP6pT 9gff15M7 /BEAAA== c1fbd928-5c80-11ee-ab26-83850402c3ce --- datefmt | 4 ++-- tests/datefmt.t | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/datefmt b/datefmt index fc70628c..bd012a92 100755 --- a/datefmt +++ b/datefmt @@ -29,7 +29,7 @@ our %Opt = ( our $progname = $0; $progname =~ s/^.*\/(.*?)$/$1/; -our $VERSION = '0.1.2'; +our $VERSION = '0.2.0'; Getopt::Long::Configure('bundling'); GetOptions( @@ -91,7 +91,7 @@ sub sec2date { 'hour' => 3600, 'day' => 86400 ); - $secc{'year'} = $secc{'day'} * 365.25; + $secc{'year'} = $secc{'day'} * 365.2425; my $retval = ""; my $years = int($ss / $secc{'year'}); $ss -= $years * $secc{'year'}; diff --git a/tests/datefmt.t b/tests/datefmt.t index 8af38ac8..dc2982e6 100755 --- a/tests/datefmt.t +++ b/tests/datefmt.t @@ -117,22 +117,22 @@ sub test_executable { 86460 => '1d:00h:01m:00s', 864000 => '10d:00h:00m:00s', 8640000 => '100d:00h:00m:00s', - 31557599 => '365d:05h:59m:59s', # 86400 * 365.25 - 1 - 31557600 => '1y:0d:00h:00m:00s', # 86400 * 365.25 - 31644000 => '1y:1d:00h:00m:00s', # 86400 * 366.25 - 31741445 => '1y:2d:03h:04m:05s', - 315575999 => '9y:365d:05h:59m:59s', - 315576000 => '10y:0d:00h:00m:00s', - 3155760000 => '100y:0d:00h:00m:00s', - 31557600000 => '1000y:0d:00h:00m:00s', - 38946942489 => '1234y:56d:07h:08m:09s', - 31557599999999 => '999999y:365d:05h:59m:59s', - 31557600000000 => '1000000y:0d:00h:00m:00s', - 31557600000001 => '1000000y:0d:00h:00m:01s', - 31557600065536 => '1000000y:0d:18h:12m:16s', - 31557600086400 => '1000000y:1d:00h:00m:00s', - 31557608596801 => '1000000y:99d:12h:00m:01s', - 315576000000000 => '10000000y:0d:00h:00m:00s', + 31556951 => '365d:05h:49m:11s', # 86400 * 365.2425 - 1 + 31556952 => '1y:0d:00h:00m:00s', # 86400 * 365.2425 + 31643352 => '1y:1d:00h:00m:00s', # 86400 * 366.2425 + 31740797 => '1y:2d:03h:04m:05s', # 86400 * (365.2425 + 2 + 3/24 + 4/1440 + 5/86400) + 315569519 => '9y:365d:05h:49m:11s', # 86400 * 10 * 365.2425 - 1 + 315569520 => '10y:0d:00h:00m:00s', # 86400 * 10 * 365.2425 + 3155695200 => '100y:0d:00h:00m:00s', # 86400 * 100 * 365.2425 + 31556952000 => '1000y:0d:00h:00m:00s', # 86400 * 1000 * 365.2425 + 38946142857 => '1234y:56d:07h:08m:09s', # 86400 * (1234 * 365.2425 + 56 + 7/24 + 8/1440 + 9/86400) + 31556951999999 => '999999y:365d:05h:49m:11s', # 86400 * 1000000 * 365.2425 - 1 + 31556952000000 => '1000000y:0d:00h:00m:00s', # 86400 * 1000000 * 365.2425 + 31556952000001 => '1000000y:0d:00h:00m:01s', # 86400 * 1000000 * 365.2425 + 1 + 31556952065536 => '1000000y:0d:18h:12m:16s', # 86400 * 1000000 * 365.2425 + 65536 + 31556952086400 => '1000000y:1d:00h:00m:00s', # 86400 * (1000000 * 365.2425 + 1) + 31556960596801 => '1000000y:99d:12h:00m:01s', # 86400 * (1000000 * 365.2425 + 99 + 12/24 + 1/86400) + 315569520000000 => '10000000y:0d:00h:00m:00s', # 86400 * 10000000 * 365.2425 ); for my $f (sort { $a <=> $b } keys %s) { -- 2.11.4.GIT