now_local Subroutine

public subroutine now_local(dt, err)

The current local date and time.

ERROR_GENERIC when the processor cannot supply the date and time; F2018 16.9.59 has date_and_time return -huge(0) for any value it does not have, and a wrong timestamp is worse than a reported failure.

Arguments

Type IntentOptional Attributes Name
type(datetime_t), intent(out) :: dt
type(error_t), intent(inout), optional :: err

Calls

proc~~now_local~~CallsGraph proc~now_local now_local proc~error_raise error_raise proc~now_local->proc~error_raise proc~error_set error_t%error_set proc~error_raise->proc~error_set

Called by

proc~~now_local~~CalledByGraph proc~now_local now_local proc~now_utc now_utc proc~now_utc->proc~now_local

Variables

Type Visibility Attributes Name Initial
integer, private :: values(DATE_AND_TIME_VALUES)

Source Code

   subroutine now_local(dt, err)
      !! The current local date and time.
      !!
      !! `ERROR_GENERIC` when the processor cannot supply the date and time;
      !! F2018 16.9.59 has `date_and_time` return `-huge(0)` for any value it
      !! does not have, and a wrong timestamp is worse than a reported failure.
      type(datetime_t), intent(out) :: dt
      type(error_t), intent(inout), optional :: err

      ! Default integer kind, as F2018 16.9.59 requires for this argument;
      ! this is the one place in PIC where a bare `integer` is correct.
      integer :: values(DATE_AND_TIME_VALUES)

      call date_and_time(values=values)

      if (any(values(1:3) == -huge(0)) .or. any(values(5:8) == -huge(0))) then
         call error_raise(err, ERROR_GENERIC, &
                          "pic_clock: the processor does not supply a date and time.")
         return
      end if

      dt%year = int(values(1), default_int)
      dt%month = int(values(2), default_int)
      dt%day = int(values(3), default_int)
      dt%hour = int(values(5), default_int)
      dt%minute = int(values(6), default_int)
      dt%second = int(values(7), default_int)
      dt%millisecond = int(values(8), default_int)

      ! The UTC offset is the field most often unavailable. Local time is
      ! still valid without it, so this is not an error here -- only `now_utc`
      ! treats its absence as one -- but it is recorded rather than flattened
      ! to zero, which would read as "on the Greenwich meridian".
      if (values(4) == -huge(0)) then
         dt%utc_offset_min = 0
         dt%utc_offset_known = .false.
      else
         dt%utc_offset_min = int(values(4), default_int)
         dt%utc_offset_known = .true.
      end if
   end subroutine now_local