days_from_civil Function

private pure function days_from_civil(y, m, d) result(days)

This internal helper uses proleptic Gregorian calendar arithmetic and maps 1970-01-01 to day zero. It is used by epoch_seconds_utc to convert the date fields returned by date_and_time into an epoch-relative day count. The function result is the signed day count relative to 1970-01-01.

Arguments

Type IntentOptional Attributes Name
integer(kind=ik), intent(in) :: y

Civil year in the proleptic Gregorian calendar.

integer(kind=ik), intent(in) :: m

Civil month in the range 1 to 12.

integer(kind=ik), intent(in) :: d

Civil day of month.

Return Value integer(kind=ik)


Called by

proc~~days_from_civil~~CalledByGraph proc~days_from_civil days_from_civil proc~epoch_seconds_utc epoch_seconds_utc proc~epoch_seconds_utc->proc~days_from_civil proc~dtimer_start timer%dtimer_start proc~dtimer_start->proc~epoch_seconds_utc proc~dtimer_stop timer%dtimer_stop proc~dtimer_stop->proc~epoch_seconds_utc proc~run_test25 run_test25 proc~run_test25->proc~dtimer_start proc~run_test25->proc~dtimer_stop proc~run_test26 run_test26 proc~run_test26->proc~dtimer_start proc~run_test26->proc~dtimer_stop proc~run_test27 run_test27 proc~run_test27->proc~dtimer_start proc~run_test27->proc~dtimer_stop proc~run_test28 run_test28 proc~run_test28->proc~dtimer_start proc~run_test28->proc~dtimer_stop proc~run_test29 run_test29 proc~run_test29->proc~dtimer_start proc~run_test29->proc~dtimer_stop proc~run_test30 run_test30 proc~run_test30->proc~dtimer_start proc~run_test30->proc~dtimer_stop program~example5 example5 program~example5->proc~dtimer_start program~example5->proc~dtimer_stop program~example6 example6 program~example6->proc~dtimer_start program~example6->proc~dtimer_stop program~check check program~check->proc~run_test25 program~check->proc~run_test26 program~check->proc~run_test27 program~check->proc~run_test28 program~check->proc~run_test29 program~check->proc~run_test30

Source Code

   pure integer(ik) function days_from_civil(y, m, d) result(days)
      integer(ik), intent(in) :: y
         !! Civil year in the proleptic Gregorian calendar.
      integer(ik), intent(in) :: m
         !! Civil month in the range 1 to 12.
      integer(ik), intent(in) :: d
         !! Civil day of month.
      integer(ik) :: y2
         !! Year adjusted so March is treated as the first month.
      integer(ik) :: m2
         !! Month adjusted so March is treated as month 3 of the adjusted year.
      integer(ik) :: era
         !! Complete 400-year era containing the adjusted year.
      integer(ik) :: yoe
         !! Year of era.
      integer(ik) :: doy
         !! Day of adjusted year.
      integer(ik) :: doe
         !! Day of era.

      y2 = y
      m2 = m
      if (m2 <= 2_ik) then
         y2 = y2 - 1_ik
         m2 = m2 + 12_ik
      end if

      era = y2 / 400_ik
      yoe = y2 - era * 400_ik
      doy = (153_ik * (m2 - 3_ik) + 2_ik) / 5_ik + d - 1_ik
      doe = yoe * 365_ik + yoe / 4_ik - yoe / 100_ik + doy

      days = era * 146097_ik + doe - 719468_ik
   end function days_from_civil