From 3f624a624a137860e080fc959d7467a76aab263d Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Thu, 16 Dec 2021 12:40:03 +0100 Subject: Fix timezone handling near year boundaries PR libfortran/98507 libgfortran/ChangeLog: * intrinsics/time_1.h: Prefer clock_gettime() over gettimeofday(). * intrinsics/date_and_time.c: Fix timezone wrapping. gcc/testsuite/ChangeLog: * gfortran.dg/date_and_time_1.f90: New file. --- gcc/testsuite/gfortran.dg/date_and_time_1.f90 | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/date_and_time_1.f90 (limited to 'gcc') diff --git a/gcc/testsuite/gfortran.dg/date_and_time_1.f90 b/gcc/testsuite/gfortran.dg/date_and_time_1.f90 new file mode 100644 index 0000000..9424e50 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/date_and_time_1.f90 @@ -0,0 +1,35 @@ +! PR libfortran/98507 +! { dg-do run } + +program demo_time_and_date + implicit none + character(8) :: date + character(10) :: time + character(5) :: zone + integer :: val(8) + integer :: h, m + + call date_and_time(values=val) + + if (val(1) < 2000 .or. val(1) > 2100) stop 1 + if (val(2) < 1 .or. val(2) > 12) stop 2 + if (val(3) < 1 .or. val(3) > 31) stop 3 + + ! Maximum offset is 14 hours (UTC+14) + if (val(4) < -14*60 .or. val(4) > 14*60) stop 4 + + if (val(5) < 0 .or. val(5) > 23) stop 5 + if (val(6) < 0 .or. val(6) > 59) stop 6 + if (val(7) < 0 .or. val(7) > 60) stop 7 + if (val(8) < 0 .or. val(8) > 999) stop 8 + + call date_and_time(zone=zone) + if (len(zone) /= 0) then + ! If ZONE is present, it should present the same information as + ! given in VALUES(4) + if (len(zone) /= 5) stop 9 + read(zone(1:3),*) h + read(zone(4:5),*) m + if (val(4) /= 60*h+m) stop 10 + endif +end -- cgit v1.1