day_of_week Function

public pure function day_of_week(dt) result(dow)

Return ISO weekday (1=Monday ... 7=Sunday).

Arguments

Type IntentOptional Attributes Name
type(datetime_type), intent(in) :: dt

Return Value integer


Source Code

    pure function day_of_week(dt) result(dow)
        !! version: experimental
        !!
        !! Return ISO weekday (1=Monday ... 7=Sunday).
        type(datetime_type), intent(in) :: dt
        integer :: dow
        integer :: y, w
        integer, parameter :: t(12) = &
            [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
        ! Guard against invalid month values
        if (dt%month < 1 .or. dt%month > 12) then
            dow = 0
            return
        end if
        y = dt%year
        if (dt%month < 3) y = y - 1
        w = mod(y + y/4 - y/100 + y/400 &
                + t(dt%month) + dt%day, 7)
        dow = mod(w + 6, 7) + 1
    end function day_of_week