diff options
author | Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2021-12-16 12:40:03 +0100 |
---|---|---|
committer | François-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2021-12-16 17:45:51 +0100 |
commit | 3f624a624a137860e080fc959d7467a76aab263d (patch) | |
tree | 91e123ccaeb048f8435a21df811edbff52fc615f /gcc | |
parent | 41cc28405c74a5ec59c6725274aaedefa9ca5887 (diff) | |
download | gcc-3f624a624a137860e080fc959d7467a76aab263d.zip gcc-3f624a624a137860e080fc959d7467a76aab263d.tar.gz gcc-3f624a624a137860e080fc959d7467a76aab263d.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gfortran.dg/date_and_time_1.f90 | 35 |
1 files changed, 35 insertions, 0 deletions
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 |