From patchwork Sun Jan 5 05:57:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 104096 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05C573858CDA for ; Sun, 5 Jan 2025 06:55:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05C573858CDA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=cs.ucla.edu header.i=@cs.ucla.edu header.a=rsa-sha256 header.s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C header.b=groGusNO X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.cs.ucla.edu (mail.cs.ucla.edu [131.179.128.66]) by sourceware.org (Postfix) with ESMTPS id 6F88E3858280 for ; Sun, 5 Jan 2025 06:00:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F88E3858280 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F88E3858280 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=131.179.128.66 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736056848; cv=none; b=nQUYDljnVCUqiv06HFBWEdUWzOVIgy13C4gaxBZv2jKMOOytI3M33irzvpGNwlhz0ei3IxJG/1U/VmeqvZKZpJpJ+n1J4l9+FF+cX/a5Y9HeI2eI+IrDDV0ieh4lST3grkIQgsyDmMqv5UjWB8C+x2nliaIpZ848byHv2Jm4K50= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736056848; c=relaxed/simple; bh=QZMzFBfqe04BEkS5TfL+s5elFjAin5UkLoXpLPYXe5I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BDrtWEg+6NN9jnxsq/XvJnJ+ENvMvX3Xv6hUgYPG/8Sj7tewmg0jqk1tz4VfCRziPpjsSF1j8sr94TmqM4hrMUATby1vlFGYzP9WqECpIPHugu/VLntLj/2vP5Tb8VyDub9JKiqMeNCnJPfNc3zN1iDTYdYn7Chq//dsjXDSUn4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F88E3858280 Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id E8ADF3C082EB5; Sat, 4 Jan 2025 22:00:47 -0800 (PST) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id frWJ7-Tt4ErV; Sat, 4 Jan 2025 22:00:47 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 85D553C082EB9; Sat, 4 Jan 2025 22:00:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 85D553C082EB9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1736056847; bh=qDcWI1uhFXRZ5kiXsifrpCoef0L+rkBAIg/9SVPbNtE=; h=From:To:Date:Message-ID:MIME-Version; b=groGusNOmgWrzEem6/c+/sC0eXpizRNG+mIV0Hlpu1WSgEj9/+e5aqZmyOXdOcWS3 Zm0o8ectykRRbiMmpGUo11DiLuFGzZ6DuErcK4d5j8zCUptDOx4NmyG07txhwaKCYq SLJxU5AcGZilYnrecJBz99Ayl6fkc/n40z4CvudX0VD4Vjh0AI+kfCGxcM3QFQ7uiB /RSuhYIYUrZWJDoRfP8jY5KaGVLCxnbIcRYL864QJZrllm3MO0XE0FPpx48d39qZsc 84IQ0F8KTqxnfDrsaYrg0u5rAf5HsJSgDZQtuJOzAL4ZeFJwtbmGNlZMaCrqQ4pW8A YiY9m7pkaEOjA== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id oU8uXp7tLqU7; Sat, 4 Jan 2025 22:00:47 -0800 (PST) Received: from wing.home (unknown [47.154.28.214]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id 6DF933C082EB5; Sat, 4 Jan 2025 22:00:47 -0800 (PST) From: Paul Eggert To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH 59/59] time: test DST adjustment for DST-less zones Date: Sat, 4 Jan 2025 21:57:34 -0800 Message-ID: <20250105055750.1668721-60-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.45.2 In-Reply-To: <01207110-bd60-46ae-9c08-fb39c2011067@cs.ucla.edu> References: <01207110-bd60-46ae-9c08-fb39c2011067@cs.ucla.edu> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Florian Weimer For zones such as UTC, it does not really make sense to perform the forced adjustment. The timezone/testdata/IST file is the compiled Asia/Kolkata zone from tz 2024a. --- time/Makefile | 1 + time/tst-mktime-dst-adjust.c | 156 +++++++++++++++++++++++++++++++++++ timezone/testdata/IST | Bin 0 -> 285 bytes 3 files changed, 157 insertions(+) create mode 100644 time/tst-mktime-dst-adjust.c create mode 100644 timezone/testdata/IST diff --git a/time/Makefile b/time/Makefile index 3e010d2c15..029322ebd7 100644 --- a/time/Makefile +++ b/time/Makefile @@ -66,6 +66,7 @@ tests := \ tst-gmtime \ tst-itimer \ tst-mktime \ + tst-mktime-dst-adjust \ tst-mktime2 \ tst-mktime3 \ tst-mktime4 \ diff --git a/time/tst-mktime-dst-adjust.c b/time/tst-mktime-dst-adjust.c new file mode 100644 index 0000000000..416ef2abcd --- /dev/null +++ b/time/tst-mktime-dst-adjust.c @@ -0,0 +1,156 @@ +/* Test mktime DST adjustment special cases. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +static int +do_test (void) +{ + TEST_COMPARE (setenv ("TZ", "UTC", 1), 0); + + { + struct tm t = + { + .tm_year = 124, + .tm_mon = 9, + .tm_mday = 1, + .tm_hour = 9, + .tm_min = 20, + .tm_sec = 53, + .tm_isdst = 1, /* Not actually true. */ + }; + TEST_COMPARE (mktime (&t), 1727774453); + } + + /* IST used DST at one point, but no longer does. */ + { + char *path = realpath ("../timezone/testdata/IST", NULL); + TEST_VERIFY (path != NULL); + TEST_COMPARE (setenv ("TZ", path, 1), 0); + free (path); + } + + { + struct tm t = + { + .tm_year = 124, + .tm_mon = 9, + .tm_mday = 1, + .tm_hour = 9, + .tm_min = 20, + .tm_sec = 53, + .tm_isdst = 0, /* Correct value. */ + }; + TEST_COMPARE (mktime (&t), 1727774453 - (int) (5.5 * 3600)); + TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600)); + TEST_COMPARE (t.tm_isdst, 0); + } + + /* This value is incorrect, but the heuristic ignores historic + DST changes. */ + { + struct tm t = + { + .tm_year = 124, + .tm_mon = 9, + .tm_mday = 1, + .tm_hour = 9, + .tm_min = 20, + .tm_sec = 53, + .tm_isdst = 1, /* Incorrect value. */ + }; + TEST_COMPARE (mktime (&t), 1727774453 - (int) (5.5 * 3600)); + TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600)); + TEST_COMPARE (t.tm_isdst, 0); + } + + /* Test using correct DST. */ + { + struct tm t = + { + .tm_year = 42, + .tm_mon = 9, + .tm_mday = 1, + .tm_hour = 9, + .tm_min = 20, + .tm_sec = 53, + .tm_isdst = 1, /* Correct value, DST was in effect. */ + }; + TEST_COMPARE (mktime (&t), -860015347); + TEST_COMPARE (t.tm_gmtoff, (int) (6.5 * 3600)); + TEST_COMPARE (t.tm_isdst, 1); + } + + /* Mismatch: DST incorrectly claimed not in effect. */ + + { + struct tm t = + { + .tm_year = 42, + .tm_mon = 9, + .tm_mday = 1, + .tm_hour = 9, + .tm_min = 20, + .tm_sec = 53, + .tm_isdst = 0, /* Incorrect value. */ + }; + TEST_COMPARE (mktime (&t), -860015347 + 3600); /* One hour added. */ + TEST_COMPARE (t.tm_gmtoff, (int) (6.5 * 3600)); + TEST_COMPARE (t.tm_isdst, 1); + } + + /* Test using correct standard time. */ + { + struct tm t = + { + .tm_year = 42, + .tm_mon = 7, + .tm_mday = 1, + .tm_hour = 9, + .tm_min = 20, + .tm_sec = 53, + .tm_isdst = 0, /* Correct value, standard time in effect. */ + }; + TEST_COMPARE (mktime (&t), -865282147); + TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600)); + TEST_COMPARE (t.tm_isdst, 0); + } + + /* Test using standard time with mismatch. */ + { + struct tm t = + { + .tm_year = 42, + .tm_mon = 7, + .tm_mday = 1, + .tm_hour = 9, + .tm_min = 20, + .tm_sec = 53, + .tm_isdst = 1, /* Incorrect value. */ + }; + TEST_COMPARE (mktime (&t), -865282147 - 3600); /* One hour subtracted. */ + TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600)); + TEST_COMPARE (t.tm_isdst, 0); + } + + return 0; +} + +#include diff --git a/timezone/testdata/IST b/timezone/testdata/IST new file mode 100644 index 0000000000000000000000000000000000000000..0014046d29a38e9b8006f746fea794d7f71eb479 GIT binary patch literal 285 zcmWHE%1kq2zzf)bvMfL>)Bq&f=kD2c>UNLD8P-CHGgFOLTq+To!N|l6gbWNpH-HKl zyxl;meIpn+7#N~67^~5w?UK*{(az6b z8-Qq#8$dM39UvOy7BCHT4~T}kiG`Vk8Rn><3m``Uod$Fi&}lqirwM?Z=7HfnE}%