Loading...
Searching...
No Matches
dcdatetimezone.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine dcdatetimesetzone (time, zone, err)
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 )

Definition at line 12 of file dcdatetimezone.f90.

13 !
14 ! 引数 *time* のタイムゾーンを *zone* へと変更します.
15 ! 実質的な日時は変更しません.
16 !
17 ! 引数 *zone* に不適切な値が与えられた場合,
18 ! エラーを発生させます.
19 ! 引数 *err* を与えている場合には *err* に .true. が返り,
20 ! プログラムは続行します.
21 !
22 use dc_types, only: string
25 & operator(-), operator(+)
27 use dc_message, only: messagenotify
28 use dc_trace, only: beginsub, endsub
29 use dc_string, only: stoi
30 implicit none
31 type(DC_DATETIME), intent(inout):: time
32 character(*), intent(in):: zone
33 logical, intent(out), optional:: err
34 type(DC_DIFFTIME):: diff, diff_in
35 integer :: stat
36 character(STRING) :: zone_in, cause_c
37 character(*), parameter :: subname = 'DCDateTimeSetZone'
38continue
39 call beginsub(subname, 'time=%c, zone=%c', &
40 & c1=trim(tochar(time)), c2=trim(zone))
41 stat = dc_noerr
42 cause_c = ''
43
44 if (.not. validzone(zone)) then
45 stat = dc_ebadtimezone
46 cause_c = zone
47 if (present(err)) then
48 call messagenotify('W', subname, &
49 & 'zone=<%c> is invalid.', &
50 & c1=trim(zone))
51 else
52 goto 999
53 end if
54 end if
55
56 call eval(time, zone = zone_in)
57 diff_in = zonetodiff(zone_in)
58 diff = zonetodiff(zone)
59
60 time = time + (diff_in - diff)
61 time % zone = zone
62
63999 continue
64 call storeerror(stat, subname, err, cause_c)
65 call endsub(subname, 'time=%c', &
66 & c1=trim(tochar(time)))
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:830
integer, parameter, public dc_noerr
Definition dc_error.f90:509
integer, parameter, public dc_ebadtimezone
Definition dc_error.f90:561
Provides kind type parameter values.
Definition dc_types.f90:49
integer, parameter, public string
Character length for string
Definition dc_types.f90:118

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

Here is the call graph for this function:

◆ dcdatetimevalidzone()

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

Definition at line 97 of file dcdatetimezone.f90.

98 !
99 ! 与えられるタイムゾーンの表記が有効であれば
100 ! .true. を, それ以外の場合は .false. を返します.
101 !
102 ! タイムゾーンの表記は '+09:00' のように, 1 文字目が '+' または '-',
103 ! 2〜3, 5〜6 文字目が数値で, 4 文字目が ':' となります.
104 !
105 implicit none
106 character(*), intent(in):: zone
107 logical:: result
108continue
109 result = .false.
110 if (len(zone) < 6) return
111 if (verify(zone(1:1), '+-') /= 0) return
112 if (verify(zone(2:3), '1234567890') /= 0) return
113 if (verify(zone(5:6), '1234567890') /= 0) return
114 if (zone(4:4) /= ':') return
115 result = .true.

◆ dcdatetimezonetodiff()

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

Definition at line 69 of file dcdatetimezone.f90.

70 !
71 ! 与えられるタイムゾーンを dc_date_types#DC_DIFFTIME 変数へと
72 ! 変換して返します. タイムゾーンの表記が無効な場合は '+00:00'
73 ! が与えられたと解釈します.
74 !
75 use dc_date_types, only: dc_difftime
77 use dc_string, only: stoi
78 implicit none
79 type(DC_DIFFTIME):: diff
80 character(*), intent(in):: zone
81 integer:: hour, min, sgn
82continue
83 if (.not. validzone(zone)) then
84 call dcdifftimecreate(diff)
85 else
86 if (zone(1:1) == '-') then
87 sgn = 1
88 else
89 sgn = -1
90 end if
91 hour = stoi(zone(2:3))
92 min = stoi(zone(5:6))
93 call dcdifftimecreate(diff, hour = hour * sgn, min = min * sgn)
94 end if