ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_dateTime::getWeekDayISO Interface Reference

Generate and return the day number of the week of a Gregorian Calendar date, assuming Monday is the first day of the week. If there is no input argument, then the current day number of the week is returned. More...

Detailed Description

Generate and return the day number of the week of a Gregorian Calendar date, assuming Monday is the first day of the week. If there is no input argument, then the current day number of the week is returned.

The internationally recognized method of conveying the day of the week is governed by ISO 8601, which uses the Zeller congruence algorithm for calculating the day of a week in a particular month and year, invented by Christian Zeller.
Monday is the official first day of the week according to ISO 8601.

Fun Facts:

  1. In the Gregorian Calendar, over a period of four hundred years, there are 97 leap years and 303 normal years.
  2. In each normal year, the weekday of January 1 advances by 1. For each leap year it advances by 2.
  3. Consequently, January 1 of year N occurs on the same day of the week as January 1 of year N + 400.
  4. Because the leap year pattern also recurs with a four hundred year cycle, a simple table of four hundred elements, and single modulus, suffices to determine the day of the week (in the Gregorian Calendar).
  5. Because 7 does not divide 400, January 1 occurs more frequently on some days than others.
  6. Similarly, in the Mathematical Gazette, vol. 53, pp.127-129, it is shown that the 13th of the month is more likely to be a Friday than any other day.
Parameters
[in]values: The input contiguous array of shape (:), of size 3 or larger, of type integer of default kind IK, containing the [year, month, day] triple of the Gregorian calendar.
For the current local date, this triple can be obtained from the Fortran intrinsic date_and_time() or getDateTime().
Only the first three elements (values(1:3)) are used to compute the output.
The ability to pass longer vectors as input is to allow the output values(1:8) of various functionalities of this module to be passed directly to the procedures under this generic interface.
(optional. It can be present if and only if all other input arguments are missing.)
[in]year: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing the year of the Gregorian calendar.
(optional. It can be present if and only if the input argument values is missing.)
[in]month: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing the month of the Gregorian calendar.
(optional. It must be present if and only if the input argument year is present.)
[in]day: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing the day of the Gregorian calendar.
(optional. It must be present if and only if the input argument month is present.)
Returns
weekday : The output scalar or array of the same shape as the input array-like arguments of type integer of default kind IK, containing the day of the week, starting with Monday as day number 1.


Possible calling interfaces

integer(IK) :: weekday
weekday = getWeekDayISO() ! current date is used.
weekday = getWeekDayISO(values(1:3)) ! values = [year, month, day]
weekday = getWeekDayISO(year, month, day) ! elemental
!
Generate and return the day number of the week of a Gregorian Calendar date, assuming Monday is the f...
This module contains classes and procedures for computing, manipulating, and styling dates and times.
Warning
The size of the input argument values(:) must be at least 3 and at most 8.
The input values for the year, month, and day must be valid values.
The input month must be a number between 1 and 12.
The input day must be a number between 1 and 31.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
The pure procedure(s) documented herein become impure when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1.
By default, these procedures are pure in release build and impure in debug and testing builds.
Remarks
The procedures under discussion are elemental. The procedures under this generic interface are non-elemental when the input argument values(:) is present.
See also
getWeekDay
WEEKDAY_NAME
WEEKDAY_NAME_ISO


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_io, only: display_type
7
8 implicit none
9
10 integer(IK) :: Values(8)
11 type(display_type) :: disp
12 disp = display_type(file = "main.out.F90")
13
14 call disp%skip()
15 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
16 call disp%show("! Get the day number of the week of a Gregorian calendar date, assuming Monday is the first day of the week.")
17 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
18 call disp%skip()
19
20 call disp%skip()
21 call disp%show("getWeekDayISO()")
22 call disp%show( getWeekDayISO() )
23 call disp%show("trim(WEEKDAY_NAME_ISO(getWeekDayISO())) ! current day of week.")
24 call disp%show( trim(WEEKDAY_NAME_ISO(getWeekDayISO())) , deliml = SK_"""" )
25 call disp%skip()
26
27 call disp%skip()
28 call disp%show("call date_and_time(values = Values(1:8))")
29 call date_and_time(values = Values(1:8))
30 call disp%show("getWeekDayISO(Values(1:3))")
31 call disp%show( getWeekDayISO(Values(1:3)) )
32 call disp%show("getWeekDayISO(year = Values(1), month = Values(2), day = Values(3))")
33 call disp%show( getWeekDayISO(year = Values(1), month = Values(2), day = Values(3)) )
34 call disp%show("SK_'Today is '//trim(WEEKDAY_NAME_ISO(getWeekDayISO(Values(1:3))))//SK_'.'")
35 call disp%show( SK_'Today is '//trim(WEEKDAY_NAME_ISO(getWeekDayISO(Values(1:3))))//SK_'.' , deliml = SK_"""" )
36 call disp%skip()
37
38 call disp%skip()
39 call disp%show("getWeekDayISO(1582_IK, 10_IK, 15_IK)")
40 call disp%show( getWeekDayISO(1582_IK, 10_IK, 15_IK) )
41 call disp%show("trim(WEEKDAY_NAME_ISO(getWeekDayISO(1582_IK, 10_IK, 15_IK)))//SK_' October 15, 1582 is the first day of the Gregorian Calendar.'")
42 call disp%show( trim(WEEKDAY_NAME_ISO(getWeekDayISO(1582_IK, 10_IK, 15_IK)))//SK_' October 15, 1582 is the first day of the Gregorian Calendar.' , deliml = SK_"""" )
43 call disp%skip()
44
45 call disp%skip()
46 call disp%show("getWeekDayISO(1_IK, 1_IK, 1_IK)")
47 call disp%show( getWeekDayISO(1_IK, 1_IK, 1_IK) )
48 call disp%show("SK_'January 1, 0001 is a '//trim(WEEKDAY_NAME_ISO(getWeekDayISO(1_IK, 1_IK, 1_IK)))//SK_' in the proleptic Gregorian Calendar.'")
49 call disp%show( SK_'January 1, 0001 is a '//trim(WEEKDAY_NAME_ISO(getWeekDayISO(1_IK, 1_IK, 1_IK)))//SK_' in the proleptic Gregorian Calendar.' , deliml = SK_"""" )
50 call disp%skip()
51
52 call disp%skip()
53 call disp%show("getWeekDayISO(2000_IK, 1_IK, 1_IK)")
54 call disp%show( getWeekDayISO(2000_IK, 1_IK, 1_IK) )
55 call disp%show("trim(WEEKDAY_NAME_ISO(getWeekDayISO(2000_IK, 1_IK, 1_IK)))")
56 call disp%show( trim(WEEKDAY_NAME_ISO(getWeekDayISO(2000_IK, 1_IK, 1_IK))) , deliml = SK_"""" )
57 call disp%skip()
58
59end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
character(9, SK), dimension(1:7), parameter WEEKDAY_NAME_ISO
The character constant vector of size 7 of length type parameter 9 containing the names of the days o...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3! Get the day number of the week of a Gregorian calendar date, assuming Monday is the first day of the week.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
8+4
9trim(WEEKDAY_NAME_ISO(getWeekDayISO())) ! current day of week.
10"Thursday"
11
12
13call date_and_time(values = Values(1:8))
14getWeekDayISO(Values(1:3))
15+4
16getWeekDayISO(year = Values(1), month = Values(2), day = Values(3))
17+4
18SK_'Today is '//trim(WEEKDAY_NAME_ISO(getWeekDayISO(Values(1:3))))//SK_'.'
19"Today is Thursday."
20
21
22getWeekDayISO(1582_IK, 10_IK, 15_IK)
23+5
24trim(WEEKDAY_NAME_ISO(getWeekDayISO(1582_IK, 10_IK, 15_IK)))//SK_' October 15, 1582 is the first day of the Gregorian Calendar.'
25"Friday October 15, 1582 is the first day of the Gregorian Calendar."
26
27
28getWeekDayISO(1_IK, 1_IK, 1_IK)
29+1
30SK_'January 1, 0001 is a '//trim(WEEKDAY_NAME_ISO(getWeekDayISO(1_IK, 1_IK, 1_IK)))//SK_' in the proleptic Gregorian Calendar.'
31"January 1, 0001 is a Monday in the proleptic Gregorian Calendar."
32
33
34getWeekDayISO(2000_IK, 1_IK, 1_IK)
35+6
36trim(WEEKDAY_NAME_ISO(getWeekDayISO(2000_IK, 1_IK, 1_IK)))
37"Saturday"
38
39
Test:
test_pm_dateTime


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, March 22, 2012, 00:00 AM, National Institute for Fusion Studies, The University of Texas Austin

Definition at line 3543 of file pm_dateTime.F90.


The documentation for this interface was generated from the following file: