Hi Pádraig,

Pádraig Brady <p...@draigbrady.com> writes:

> Right, though it might be better to use \uXXXX char specifiers
> than raw UTF-8 encodings. Something like:
>
> # All months that have 31 days have names that end with "คม".
> days_31_suffix=$(env LC_ALL=th_TH.UTF-8 printf '\u0E04\u0E21')
> test $(printf '%s' "$days_31_suffix" | wc -c) = 6 || skip_ 'bad suffix'
> for month in 01 03 05 07 08 10 12; do
>   date --date=$current_year-$month-01 +%B | grep "$days_31_suffix$" || fail=1
> done

Thanks, that looks good to me.

> Sorry for the tardy response. I was on holidays.

No problem at all.

> But you can just use the explicit charmap, like:
>
>  $ LC_ALL=th_TH.UTF-8 locale charmap
>  UTF-8
>  $ LC_ALL=am_ET.UTF-8 locale charmap
>  UTF-8

Cool, sounds good.

I pushed this patch with the removal of the "==" bashism, your printf
recommendation, and the locale check. Plus I added two checks that test
the behavior of Bruno's patch, that --iso-8601 and --rfc-3339 use the
Gregorian calendar in the Thai locale.

> thanks for working on this

No problem, thanks to you and Berny for checking. I'll write tests for
the other two locales tomorrow.

Collin

>From 5ab05e5a36a45f6efe0118eb115746830cc1859c Mon Sep 17 00:00:00 2001
Message-ID: <5ab05e5a36a45f6efe0118eb115746830cc1859c.1753158930.git.collin.fu...@gmail.com>
From: Collin Funk <collin.fu...@gmail.com>
Date: Thu, 17 Jul 2025 19:42:30 -0700
Subject: [PATCH] tests: date: add tests for the Thai solar calendar

* tests/date/date-thailand.sh: New file.
* tests/local.mk (all_tests): Add the test.
---
 tests/date/date-thailand.sh | 46 +++++++++++++++++++++++++++++++++++++
 tests/local.mk              |  1 +
 2 files changed, 47 insertions(+)
 create mode 100755 tests/date/date-thailand.sh

diff --git a/tests/date/date-thailand.sh b/tests/date/date-thailand.sh
new file mode 100755
index 000000000..18a49f27c
--- /dev/null
+++ b/tests/date/date-thailand.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# Verify the Thai solar calendar is used with the Thai locale.
+
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ date printf
+
+# Current year in the Gregorian calendar.
+current_year=$(LC_ALL=C date +%Y)
+
+export LC_ALL=th_TH.UTF-8
+
+if test "$(locale charmap 2>/dev/null)" != UTF-8; then
+  skip_ "Thai UTF-8 locale not available"
+fi
+
+# Since 1941, the year in the Thai solar calendar is the Gregorian year plus
+# 543.
+test $(date +%Y) = $(($current_year + 543)) || fail=1
+
+# All months that have 31 days have names that end with "คม".
+days_31_suffix=$(env printf '\u0E04\u0E21')
+test $(printf '%s' "$days_31_suffix" | wc -c) = 6 || skip_ 'bad suffix'
+for month in 01 03 05 07 08 10 12; do
+  date --date=$current_year-$month-01 +%B | grep "$days_31_suffix$" || fail=1
+done
+
+# Check that --iso-8601 and --rfc-3339 uses the Gregorian calendar.
+case $(date --iso-8601=hours) in $current_year-*) ;; *) fail=1 ;; esac
+case $(date --rfc-3339=date) in $current_year-*) ;; *) fail=1 ;; esac
+
+Exit $fail
diff --git a/tests/local.mk b/tests/local.mk
index dd07032da..4cd1a34d2 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -310,6 +310,7 @@ all_tests =					\
   tests/csplit/csplit-suppress-matched.pl	\
   tests/date/date-debug.sh			\
   tests/date/date-sec.sh			\
+  tests/date/date-thailand.sh			\
   tests/date/date-tz.sh				\
   tests/misc/dircolors.pl			\
   tests/misc/dirname.pl				\
-- 
2.50.1

Reply via email to