dcdatetimezone.f90
Go to the documentation of this file.
1 !== タイムゾーンに関する手続き
2 !
3 ! Authors:: Yasuhiro MORIKAWA
4 ! Version:: $Id: dcdatetimezone.f90,v 1.2 2009-05-25 10:01:34 morikawa Exp $
5 ! Tag Name:: $Name: $
6 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
7 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
8 !
9 ! このファイルで提供される手続き群は dc_date モジュールにて提供されます。
10 !
11 
12 subroutine dcdatetimesetzone(time, zone, err)
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'
38 continue
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 
63 999 continue
64  call storeerror(stat, subname, err, cause_c)
65  call endsub(subname, 'time=%c', &
66  & c1=trim(tochar(time)))
67 end subroutine dcdatetimesetzone
68 
69 function dcdatetimezonetodiff(zone) result(diff)
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
82 continue
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
95 end function dcdatetimezonetodiff
96 
97 function dcdatetimevalidzone(zone) result(result)
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
108 continue
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.
116 end function dcdatetimevalidzone
integer, parameter, public dc_ebadtimezone
Definition: dc_error.f90:561
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
subroutine dcdatetimesetzone(time, zone, err)
logical function dcdatetimevalidzone(zone)
subroutine, public beginsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca, version)
Definition: dc_trace.f90:351
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
type(dc_difftime) function dcdatetimezonetodiff(zone)
subroutine, public endsub(name, fmt, i, r, d, L, n, c1, c2, c3, ca)
Definition: dc_trace.f90:446
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118