From: Lucas Gabriel Vuotto Subject: Replace date, strftime %G-%m-%d with %F To: gameoftrees@openbsd.org Date: Tue, 23 Apr 2024 18:29:14 +0000 Hi, As the subject reads, use the more predictable %F, aka %Y-%m-%d, instead of %G-%m-%d. The latter follows the definition of ISO-8601 week-based year, which is weird. Citing what POSIX [0] says about it: > %g, %G, and %V give values according to the ISO 8601:2000 standard > week-based year. In this system, weeks begin on a Monday and week 1 of > the year is the week that includes January 4th, which is also the week > that includes the first Thursday of the year, and is also the first > week that contains at least four days in the year. If the first Monday > of January is the 2nd, 3rd, or 4th, the preceding days are part of the > last week of the preceding year; thus, for Saturday 2nd January 1999, > %G is replaced by 1998 and %V is replaced by 53. If December 29th, > 30th, or 31st is a Monday, it and any following days are part of week > 1 of the following year. Thus, for Tuesday 30th December 1997, %G is > replaced by 1998 and %V is replaced by 01. In particular, 2024 is one of such years with weird behaviour: $ date -jf %Y-%m-%d +"%F %G-%m-%d" 2024-12-30 2024-12-30 2025-12-30 The changes were performed mechanically with sed -i 's/%G-%m-%d/%F/g' $(grep -Flr %G-%m-%d) All the uses of %G-%m-%d come from either date(1) or strftime(3). No other %G is left around the repo. Given that %F is shorter, I unfolded a couple of lines. make regress is happy. Lucas [0]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html ----------------------------------------------- commit dac05127ab3a70fb5cc6a76467ff101fe583b0ee (strftime-G) from: Lucas Gabriel Vuotto date: Tue Apr 23 18:27:34 2024 UTC Replace date, strftime %G-%m-%d with %F The %G specifier is the ISO-8601 week-based year, which differs from the calendar year under certain circumstances. Replace it with %Y to follow the calendar year. Given that %F is %Y-%m-%d, use %F instead. diff b93f334d743a91156b4558df907bd59a0c85cf69 dac05127ab3a70fb5cc6a76467ff101fe583b0ee commit - b93f334d743a91156b4558df907bd59a0c85cf69 commit + dac05127ab3a70fb5cc6a76467ff101fe583b0ee blob - 38191d6109e5f5caf08654969f4f3af3d9fb2c70 blob + 8371183b94f386e42d65020ff1fed931a40906e3 --- cvg/cvg.c +++ cvg/cvg.c @@ -3552,7 +3552,7 @@ print_commit_oneline(struct got_commit_object *commit, err = got_error_from_errno("gmtime_r"); goto done; } - if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0) { + if (strftime(datebuf, sizeof(datebuf), "%F ", &tm) == 0) { err = got_error(GOT_ERR_NO_SPACE); goto done; } @@ -4989,8 +4989,7 @@ blame_cb(void *arg, int nlines, int lineno, committer_time = got_object_commit_get_committer_time(commit); if (gmtime_r(&committer_time, &tm) == NULL) return got_error_from_errno("gmtime_r"); - if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d", - &tm) == 0) { + if (strftime(bline->datebuf, sizeof(bline->datebuf), "%F", &tm) == 0) { err = got_error(GOT_ERR_NO_SPACE); goto done; } blob - b55e991971271638732739463b3a95ee39f126af blob + 9b22bd01524107cae5a5dc3a2b85913cadb5bd7b --- got/got.c +++ got/got.c @@ -4252,7 +4252,7 @@ print_commit_oneline(struct got_commit_object *commit, err = got_error_from_errno("gmtime_r"); goto done; } - if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0) { + if (strftime(datebuf, sizeof(datebuf), "%F ", &tm) == 0) { err = got_error(GOT_ERR_NO_SPACE); goto done; } @@ -5728,8 +5728,7 @@ blame_cb(void *arg, int nlines, int lineno, committer_time = got_object_commit_get_committer_time(commit); if (gmtime_r(&committer_time, &tm) == NULL) return got_error_from_errno("gmtime_r"); - if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d", - &tm) == 0) { + if (strftime(bline->datebuf, sizeof(bline->datebuf), "%F", &tm) == 0) { err = got_error(GOT_ERR_NO_SPACE); goto done; } @@ -10968,7 +10967,7 @@ get_commit_brief_str(char **brief_str, struct got_comm committer_time = got_object_commit_get_committer_time(commit); if (gmtime_r(&committer_time, &tm) == NULL) return got_error_from_errno("gmtime_r"); - if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d", &tm) == 0) + if (strftime(datebuf, sizeof(datebuf), "%F", &tm) == 0) return got_error(GOT_ERR_NO_SPACE); author0 = strdup(got_object_commit_get_author(commit)); blob - 16f1d741593d53dc9c972d53a4536edabae0301a blob + 931efceb0756948a547a10f4e697267b1e11010c --- gotd/libexec/got-notify-email/got-notify-email.c +++ gotd/libexec/got-notify-email/got-notify-email.c @@ -243,7 +243,7 @@ print_date(int s, char *date, int shortfmt) return got_poll_write_full(s, " UTC\n", 5); } - if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0) + if (strftime(datebuf, sizeof(datebuf), "%F ", &tm) == 0) return got_error_set_errno(EINVAL, "invalid timestamp"); return got_poll_write_full(s, datebuf, strlen(datebuf)); } blob - bd3939fbbae66ba3fc54ef4ac319959561b56a2c blob + 5bcdf61f67c447df889e0dce4ed81ce7e39d19e0 --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -944,8 +944,7 @@ got_gotweb_blame_cb(void *arg, int nlines, int lineno, committer_time = got_object_commit_get_committer_time(commit); if (gmtime_r(&committer_time, &tm) == NULL) return got_error_from_errno("gmtime_r"); - if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d", - &tm) == 0) { + if (strftime(bline->datebuf, sizeof(bline->datebuf), "%F", &tm) == 0) { err = got_error(GOT_ERR_NO_SPACE); goto done; } blob - 4281311847e1767c625823074c5208dc9f177123 blob + d60fc3d989f80b6803c66daddd2280f9ac6bee96 --- regress/cmdline/blame.sh +++ regress/cmdline/blame.sh @@ -65,7 +65,7 @@ test_blame_basic() { local short_commit2=`trim_obj_id 32 $commit2` local short_commit3=`trim_obj_id 32 $commit3` - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected @@ -113,7 +113,7 @@ test_blame_tag() { local short_commit1=`trim_obj_id 32 $commit1` local short_commit2=`trim_obj_id 32 $commit2` - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected @@ -149,7 +149,7 @@ test_blame_file_single_line() { local short_commit1=`trim_obj_id 32 $commit1` - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout @@ -184,7 +184,7 @@ test_blame_file_single_line_no_newline() { local short_commit1=`trim_obj_id 32 $commit1` - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout @@ -213,7 +213,7 @@ test_blame_all_lines_replaced() { (cd $testroot/wt && got blame alpha > $testroot/stdout) - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit1 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected @@ -268,7 +268,7 @@ test_blame_lines_shifted_up() { (cd $testroot/wt && got blame alpha > $testroot/stdout) - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit3 $d $GOT_AUTHOR_8 foo" >> $testroot/stdout.expected @@ -327,7 +327,7 @@ test_blame_lines_shifted_down() { (cd $testroot/wt && got blame alpha > $testroot/stdout) - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "01) $short_commit1 $d $GOT_AUTHOR_8 1" \ > $testroot/stdout.expected echo "02) $short_commit1 $d $GOT_AUTHOR_8 2" \ @@ -400,7 +400,7 @@ EOF local commit1=`git_show_head $testroot/repo` local short_commit1=`trim_obj_id 32 $commit1` local author_time1=`git_show_author_time $testroot/repo` - local d1=`date -u -r $author_time1 +"%G-%m-%d"` + local d1=`date -u -r $author_time1 +"%F"` cat > $testroot/wt/alpha < $testroot/wt/alpha < $testroot/wt/alpha < $testroot/stdout) @@ -724,7 +724,7 @@ test_blame_added_on_branch() { local short_commit2=`trim_obj_id 32 $commit2` local short_commit3=`trim_obj_id 32 $commit3` - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected @@ -795,7 +795,7 @@ test_blame_symlink() { return 1 fi - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit0 $d $GOT_AUTHOR_8 alpha" \ > $testroot/stdout.expected @@ -816,7 +816,7 @@ test_blame_symlink() { return 1 fi - d=`date -u -r $author_time +"%G-%m-%d"` + d=`date -u -r $author_time +"%F"` echo "1) $short_commit0 $d $GOT_AUTHOR_8 beta" \ > $testroot/stdout.expected @@ -966,10 +966,10 @@ EOF (cd $testroot/wt && got blame alpha > $testroot/stdout) - d1=`date -u -r $author_time1 +"%G-%m-%d"` - d2=`date -u -r $author_time2 +"%G-%m-%d"` - d4=`date -u -r $author_time4 +"%G-%m-%d"` - d5=`date -u -r $author_time5 +"%G-%m-%d"` + d1=`date -u -r $author_time1 +"%F"` + d2=`date -u -r $author_time2 +"%F"` + d4=`date -u -r $author_time4 +"%F"` + d5=`date -u -r $author_time5 +"%F"` echo "1) $short_commit5 $d5 $GOT_AUTHOR_8 X" > $testroot/stdout.expected echo "2) $short_commit1 $d1 $GOT_AUTHOR_8 A" >> $testroot/stdout.expected echo "3) $short_commit1 $d1 $GOT_AUTHOR_8 B" >> $testroot/stdout.expected @@ -1042,7 +1042,7 @@ test_blame_commit_keywords() { done local author_time=$(git_show_author_time "$repo") - local d=$(date -u -r $author_time +"%G-%m-%d") + local d=$(date -u -r $author_time +"%F") got blame -r "$repo" -c:head:-8 alpha > "$testroot/stdout" echo "1) $(pop_idx 1 $@) $d $GOT_AUTHOR_8 alpha" > \ blob - 13dd31e4feec963e558e3e0eebbcfac22c15c741 blob + b0adfd36a468c7760119682e77e3c30152401592 --- regress/cmdline/histedit.sh +++ regress/cmdline/histedit.sh @@ -156,10 +156,10 @@ test_histedit_no_op() { # We should have a backup of old commits (cd $testroot/repo && got histedit -l > $testroot/stdout) - d_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"` + d_orig1=`date -u -r $old_author_time1 +"%F"` d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"` - d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"` - d_orig=`date -u -r $orig_author_time +"%G-%m-%d"` + d_new2=`date -u -r $new_author_time2 +"%F"` + d_orig=`date -u -r $orig_author_time +"%F"` cat > $testroot/stdout.expected < /dev/null) local commit_id2=`git_show_head $testroot/repo` local author_time2=`git_show_author_time $testroot/repo` - d=`date -u -r $author_time1 +"%G-%m-%d"` + d=`date -u -r $author_time1 +"%F"` printf "$d %-7s test oneline\n" master > $testroot/stdout.expected - d=`date -u -r $author_time2 +"%G-%m-%d"` + d=`date -u -r $author_time2 +"%F"` printf "$d %.7s test oneline\n" $commit_id1 >> $testroot/stdout.expected (cd $testroot/repo && got log -s | head -n 2 > $testroot/stdout) @@ -963,7 +963,7 @@ EOF test_log_commit_keywords() { local testroot=$(test_init log_commit_keywords) local commit_time=`git_show_author_time $testroot/repo` - local d=`date -u -r $commit_time +"%G-%m-%d"` + local d=`date -u -r $commit_time +"%F"` set -- "$(git_show_head $testroot/repo)" @@ -1280,11 +1280,11 @@ test_log_toposort() { local short_commit2=`trim_obj_id 33 $commit2` local short_commit3=`trim_obj_id 33 $commit3` - d_0=`date -u -r $author_time0 +"%G-%m-%d"` - d_1=`date -u -r $author_time1 +"%G-%m-%d"` - d_2=`date -u -r $author_time2 +"%G-%m-%d"` - d_3=`date -u -r $author_time3 +"%G-%m-%d"` - d_m=`date -u -r $merge_time +"%G-%m-%d"` + d_0=`date -u -r $author_time0 +"%F"` + d_1=`date -u -r $author_time1 +"%F"` + d_2=`date -u -r $author_time2 +"%F"` + d_3=`date -u -r $author_time3 +"%F"` + d_m=`date -u -r $merge_time +"%F"` got log -r $testroot/repo -s -b -t > $testroot/stdout cat > $testroot/stdout.expected < $testroot/stdout) d_orig2=`date -u -r $orig_author_time2 +"%a %b %e %X %Y UTC"` - d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"` - d_0=`date -u -r $commit0_author_time +"%G-%m-%d"` + d_new2=`date -u -r $new_author_time2 +"%F"` + d_0=`date -u -r $commit0_author_time +"%F"` cat > $testroot/stdout.expected < /dev/null) local commit_id4=`git_show_head $testroot/repo` local author_time=`git_show_author_time $testroot/repo` - local ymd=`date -u -r $author_time +"%G-%m-%d"` + local ymd=`date -u -r $author_time +"%F"` cat <$TOG_TEST_SCRIPT WAIT_FOR_UI wait for blame to finish @@ -83,7 +83,7 @@ test_blame_commit_keywords() local wt="$testroot/wt" local id=$(git_show_head "$repo") local author_time=$(git_show_author_time "$repo") - local ymd=$(date -u -r $author_time +"%G-%m-%d") + local ymd=$(date -u -r $author_time +"%F") set -- "$id" @@ -168,7 +168,7 @@ test_blame_commit_keywords() done author_time=$(git_show_author_time "$repo") - ymd=$(date -u -r $author_time +"%G-%m-%d") + ymd=$(date -u -r $author_time +"%F") # :base:- keyword in work tree cat <<-EOF >$testroot/view.expected blob - bc8e1f86537b6f5d928c84cdd4144af824835317 blob + aca1f106300cbd9e2079fa5bedad94acb5af6f36 --- regress/tog/log.sh +++ regress/tog/log.sh @@ -23,7 +23,7 @@ test_log_hsplit_diff() local head_id=`git_show_head $testroot/repo` local author_time=`git_show_author_time $testroot/repo` local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` - local ymd=`date -u -r $author_time +"%G-%m-%d"` + local ymd=`date -u -r $author_time +"%F"` cat <$TOG_TEST_SCRIPT KEY_ENTER open diff view of selected commit @@ -78,7 +78,7 @@ test_log_vsplit_diff() local head_id=`git_show_head $testroot/repo` local author_time=`git_show_author_time $testroot/repo` local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` - local ymd=`date -u -r $author_time +"%G-%m-%d"` + local ymd=`date -u -r $author_time +"%F"` local blobid_alpha=`get_blob_id $testroot/repo "" alpha` local blobid_beta=`get_blob_id $testroot/repo "" beta` @@ -134,7 +134,7 @@ test_log_show_author() local head_id=`git_show_head $testroot/repo` local author_time=`git_show_author_time $testroot/repo` local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` - local ymd=`date -u -r $author_time +"%G-%m-%d"` + local ymd=`date -u -r $author_time +"%F"` local head_id_len8=`trim_obj_id 32 $head_id` echo "mod alpha" > $testroot/repo/alpha @@ -177,7 +177,7 @@ test_log_scroll_right() local head_id=`git_show_head $testroot/repo` local author_time=`git_show_author_time $testroot/repo` local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` - local ymd=`date -u -r $author_time +"%G-%m-%d"` + local ymd=`date -u -r $author_time +"%F"` local msg="scroll this log message to the right four characters" local scrolled_msg="ter] scroll this log message to the right four character" @@ -217,7 +217,7 @@ test_log_hsplit_ref() local head_id=`git_show_head $testroot/repo` local author_time=`git_show_author_time $testroot/repo` local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` - local ymd=`date -u -r $author_time +"%G-%m-%d"` + local ymd=`date -u -r $author_time +"%F"` cat <$TOG_TEST_SCRIPT R open ref view @@ -258,7 +258,7 @@ test_log_hsplit_tree() local head_id=`git_show_head $testroot/repo` local author_time=`git_show_author_time $testroot/repo` local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` - local ymd=`date -u -r $author_time +"%G-%m-%d"` + local ymd=`date -u -r $author_time +"%F"` cat <$TOG_TEST_SCRIPT T open tree view @@ -361,7 +361,7 @@ test_log_commit_keywords() local wt="$testroot/wt" local id=$(git_show_head "$repo") local author_time=$(git_show_author_time "$repo") - local ymd=$(date -u -r $author_time +"%G-%m-%d") + local ymd=$(date -u -r $author_time +"%F") set -- "$id" @@ -519,7 +519,7 @@ test_log_show_base_commit() local head_id=$(git_show_head "$repo") local author_time=$(git_show_author_time "$repo") - local ymd=$(date -u -r "$author_time" +"%G-%m-%d") + local ymd=$(date -u -r "$author_time" +"%F") # check up-to-date base commit marker prefixes base commit log message cat <<-EOF >$TOG_TEST_SCRIPT @@ -638,7 +638,7 @@ test_log_limit_view() return 1 fi local author_time=$(git_show_author_time "$repo") - local ymd=$(date -u -r $author_time +"%G-%m-%d") + local ymd=$(date -u -r $author_time +"%F") local id=$(git_show_head "$repo") # check base commit marker is not drawn @@ -698,7 +698,7 @@ test_log_search() done local author_time=$(git_show_author_time "$repo") - local ymd=$(date -u -r $author_time +"%G-%m-%d") + local ymd=$(date -u -r $author_time +"%F") cat <<-EOF >$TOG_TEST_SCRIPT /alpha commit 8 blob - 49be7dc0e431407602c4dba0ac7030028d5a567e blob + ef69429eb4ba2e561f99ebcf790e0f123f4d05cb --- tog/tog.c +++ tog/tog.c @@ -2459,7 +2459,7 @@ draw_commit(struct tog_view *view, struct commit_queue committer_time = got_object_commit_get_committer_time(commit); if (gmtime_r(&committer_time, &tm) == NULL) return got_error_from_errno("gmtime_r"); - if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0) + if (strftime(datebuf, sizeof(datebuf), "%F ", &tm) == 0) return got_error(GOT_ERR_NO_SPACE); if (avail <= date_display_cols) @@ -8790,7 +8790,7 @@ show_ref_view(struct tog_view *view) free(id); if (gmtime_r(&t, &tm) == NULL) return got_error_from_errno("gmtime_r"); - if (strftime(ymd, sizeof(ymd), "%G-%m-%d ", &tm) == 0) + if (strftime(ymd, sizeof(ymd), "%F ", &tm) == 0) return got_error(GOT_ERR_NO_SPACE); } if (got_ref_is_symbolic(re->ref)) {