gtool5 Fortran 90/95 Library 1.0.0-rc5
日本語
Loading...
Searching...
No Matches
dcdatetimezone.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine dcdatetimesetzone (time, zone, err)
 Procedures for timezone handling.
type(dc_difftime) function dcdatetimezonetodiff (zone)
logical function dcdatetimevalidzone (zone)

Function/Subroutine Documentation

◆ dcdatetimesetzone()

subroutine dcdatetimesetzone ( type(dc_datetime), intent(inout) time,
character(*), intent(in) zone,
logical, intent(out), optional err )

Procedures for timezone handling.

Author
Yasuhiro MORIKAWA

Procedures described in this file are provided from "dc_date" module.

Set the timezone of a datetime

Change the timezone of the argument time to zone. The actual datetime is not changed.

If an invalid value is given to the argument zone, an error is raised. If the argument err is given, .true. is returned to err and the program continues.

Parameters
[in,out]timeDatetime to change timezone
[in]zoneTimezone to set (e.g., "+09:00")
[out]errException handling flag

Definition at line 53 of file dcdatetimezone.f90.

54
55 use dc_types, only: string
58 & operator(-), operator(+)
60 use dc_message, only: messagenotify
61 use dc_trace, only: beginsub, endsub
62 use dc_string, only: stoi
63 implicit none
64 type(DC_DATETIME), intent(inout):: time
65 character(*), intent(in):: zone
66 logical, intent(out), optional:: err
67 type(DC_DIFFTIME):: diff, diff_in
68 integer :: stat
69 character(STRING) :: zone_in, cause_c
70 character(*), parameter :: subname = 'DCDateTimeSetZone'
71continue
72 call beginsub(subname, 'time=%c, zone=%c', &
73 & c1=trim(tochar(time)), c2=trim(zone))
74 stat = dc_noerr
75 cause_c = ''
76
77 if (.not. validzone(zone)) then
78 stat = dc_ebadtimezone
79 cause_c = zone
80 if (present(err)) then
81 call messagenotify('W', subname, &
82 & 'zone=<%c> is invalid.', &
83 & c1=trim(zone))
84 else
85 goto 999
86 end if
87 end if
88
89 call eval(time, zone = zone_in)
90 diff_in = zonetodiff(zone_in)
91 diff = zonetodiff(zone)
92
93 time = time + (diff_in - diff)
94 time % zone = zone
95
96999 continue
97 call storeerror(stat, subname, err, cause_c)
98 call endsub(subname, 'time=%c', &
99 & c1=trim(tochar(time)))
Interface declarations for procedures provided from dc_date.
Derived types and parameters for date and time.
Error handling module.
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public dc_noerr
Error storage variables
Definition dc_error.f90:468
integer, parameter, public dc_ebadtimezone
Definition dc_error.f90:538
Message output module.
Handling character types.
Definition dc_string.f90:83
Debug tracing module.
Definition dc_trace.f90:150
subroutine, public beginsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca, version)
Definition dc_trace.f90:476
subroutine, public endsub(name, fmt, i, r, d, l, n, c1, c2, c3, ca)
Definition dc_trace.f90:599
Provides kind type parameter values.
Definition dc_types.f90:55
integer, parameter, public string
Character length for string
Definition dc_types.f90:137

References dc_trace::beginsub(), dc_error::dc_ebadtimezone, dc_error::dc_noerr, dc_trace::endsub(), dc_error::storeerror(), and dc_types::string.

Here is the call graph for this function:

◆ dcdatetimevalidzone()

logical function dcdatetimevalidzone ( character(*), intent(in) zone)

Check if timezone notation is valid

Returns .true. if the given timezone notation is valid, .false. otherwise.

The timezone notation should be like '+09:00', where the 1st character is '+' or '-', 2nd-3rd and 5th-6th characters are digits, and 4th character is ':'.

Parameters
[in]zoneTimezone string to check
Returns
.true. if valid, .false. otherwise

Definition at line 173 of file dcdatetimezone.f90.

174
175 implicit none
176 character(*), intent(in):: zone
177 logical:: result
178continue
179 result = .false.
180 if (len(zone) < 6) return
181 if (verify(zone(1:1), '+-') /= 0) return
182 if (verify(zone(2:3), '1234567890') /= 0) return
183 if (verify(zone(5:6), '1234567890') /= 0) return
184 if (zone(4:4) /= ':') return
185 result = .true.

◆ dcdatetimezonetodiff()

type(dc_difftime) function dcdatetimezonetodiff ( character(*), intent(in) zone)

Convert timezone string to DC_DIFFTIME

Convert the given timezone to a dc_date_types#DC_DIFFTIME variable and return it. If the timezone notation is invalid, it is interpreted as if '+00:00' was given.

Parameters
[in]zoneTimezone string (e.g., "+09:00")
Returns
Time difference corresponding to the timezone

Definition at line 123 of file dcdatetimezone.f90.

124
125 use dc_date_types, only: dc_difftime
127 use dc_string, only: stoi
128 implicit none
129 type(DC_DIFFTIME):: diff
130 character(*), intent(in):: zone
131 integer:: hour, min, sgn
132continue
133 if (.not. validzone(zone)) then
134 call dcdifftimecreate(diff)
135 else
136 if (zone(1:1) == '-') then
137 sgn = 1
138 else
139 sgn = -1
140 end if
141 hour = stoi(zone(2:3))
142 min = stoi(zone(5:6))
143 call dcdifftimecreate(diff, hour = hour * sgn, min = min * sgn)
144 end if