now_utc Subroutine

public subroutine now_utc(dt, err)

The current date and time in UTC, with utc_offset_min zero.

ERROR_GENERIC when the processor cannot supply its offset from UTC, rather than silently returning local time labelled as UTC.

Arguments

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

Calls

proc~~now_utc~~CallsGraph proc~now_utc now_utc proc~datetime_from_unix_ms datetime_from_unix_ms proc~now_utc->proc~datetime_from_unix_ms proc~error_has_error error_t%error_has_error proc~now_utc->proc~error_has_error proc~error_raise error_raise proc~now_utc->proc~error_raise proc~now_local now_local proc~now_utc->proc~now_local proc~unix_time_ms unix_time_ms proc~now_utc->proc~unix_time_ms proc~civil_from_days civil_from_days proc~datetime_from_unix_ms->proc~civil_from_days proc~error_set error_t%error_set proc~error_raise->proc~error_set proc~now_local->proc~error_raise proc~days_from_civil days_from_civil proc~unix_time_ms->proc~days_from_civil

Variables

Type Visibility Attributes Name Initial
type(datetime_t), private :: local
integer(kind=int64), private :: utc_ms
integer, private :: values(DATE_AND_TIME_VALUES)

Source Code

   subroutine now_utc(dt, err)
      !! The current date and time in UTC, with `utc_offset_min` zero.
      !!
      !! `ERROR_GENERIC` when the processor cannot supply its offset from UTC,
      !! rather than silently returning local time labelled as UTC.
      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)
      type(datetime_t) :: local
      integer(int64) :: utc_ms

      call date_and_time(values=values)
      if (values(4) == -huge(0)) then
         call error_raise(err, ERROR_GENERIC, &
                          "pic_clock: the processor does not supply its offset from UTC.")
         return
      end if

      call now_local(local, err)
      if (present(err)) then
         if (err%has_error()) return
      end if

      utc_ms = unix_time_ms(local)
      dt = datetime_from_unix_ms(utc_ms)
   end subroutine now_utc