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

Generate and return the Week Number, i.e., the number of weeks of the input year until and including the week containing the specified input Gregorian date. More...

Detailed Description

Generate and return the Week Number, i.e., the number of weeks of the input year until and including the week containing the specified input Gregorian date.

The Week Number is important for constructing the ISO week date system, a leap week calendar system that is part of the \(\ms{ISO 8601}\) date and time standard issued by the International Organization for Standardization (ISO) since 1988 It is (mainly) used in government and business for fiscal years, as well as in timekeeping.
The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.

The \(\ms{ISO 8601}\) definition for week number 01 is the week with the first Thursday of January of the Gregorian year in it.
The following definitions for the first week of the year are mutually equivalent, since **the ISO week starts with Monday
:

  1. It is the first week with a majority (4 or more) of its days in January.
  2. Its first day is the Monday nearest to January 1st.
  3. It has January 4th in it. Hence,
    1. the earliest possible first week extends from Monday December 29th of the previous Gregorian year to Sunday January 4th,
    2. the latest possible first week extends from Monday 4 January to Sunday January 10th.
  4. It has the year's first working day in it, if Saturdays, Sundays and January 1st are not working days.
  5. If January 1st is on a Monday, Tuesday, Wednesday or Thursday, it is in W01.
  6. If January 1st is on a Friday, it is part of W53 of the previous year.
  7. If January 1st is on a Saturday, it is part of the last week of the previous year which is numbered W52 in a common year and W53 in a leap year.
  8. If it is on a Sunday, it is part of W52 of the previous year.

Returning the correct result requires taking into account the possibility of leap years.

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
weekNumber : The output scalar of type integer of default kind IK, containing the ordinal week of the specified Gregorian Calendar date.
If all input arguments are missing, the ordinal week corresponding to the current Gregorian date is returned.


Possible calling interfaces

integer(IK) :: weekNumber
weekNumber = getWeekNumber() ! use the current date.
weekNumber = getWeekNumber(values(1:3)) ! values = [year, month, day]
weekNumber = getWeekNumber(year, month, day) ! elemental
!
Generate and return the Week Number, i.e., the number of weeks of the input year until and including ...
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. The procedures under this generic interface are always impure when all input arguments are missing.
Remarks
The procedures under discussion are elemental. The procedures under this generic interface are non-elemental when all input arguments are missing or only the input argument values(:) is present.
See also
isLastDayInMonth


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_io, only: display_type
5 use pm_dateTime, only: getDateTime
7
8 implicit none
9
10 integer(IK) :: Values(8)
11
12 type(display_type) :: disp
13 disp = display_type(file = "main.out.F90")
14
15 call disp%skip()
16 call disp%show("getDateTime()")
17 call disp%show( getDateTime() )
18 call disp%show("getWeekNumber()")
19 call disp%show( getWeekNumber() )
20 call disp%skip()
21
22 call disp%skip()
23 call disp%show("call date_and_time(values = Values)")
24 call date_and_time(values = Values)
25 call disp%show("Values(1:3)")
26 call disp%show( Values(1:3) )
27 call disp%show("getWeekNumber(Values(1:3))")
28 call disp%show( getWeekNumber(Values(1:3)) )
29 call disp%skip()
30
31 call disp%skip()
32 call disp%show("getWeekNumber(+2022, +5, +8) ! Sunday: 18 weeks so far with majority of days in 2022.")
33 call disp%show( getWeekNumber(+2022, +5, +8) )
34 call disp%skip()
35
36 call disp%skip()
37 call disp%show("getWeekNumber(+2022, +5, +9) ! Monday: 19 weeks so far with majority of days in 2022.")
38 call disp%show( getWeekNumber(+2022, +5, +9) )
39 call disp%skip()
40
41 call disp%skip()
42 call disp%show("getWeekNumber(+2022, +5, +12) ! Thursday: 19 weeks so far with majority of days in 2022.")
43 call disp%show( getWeekNumber(+2022, +5, +12) )
44 call disp%skip()
45
46 call disp%skip()
47 call disp%show("getWeekNumber(-4713_IK, 11_IK, 24_IK)")
48 call disp%show( getWeekNumber(-4713_IK, 11_IK, 24_IK) )
49 call disp%skip()
50
51 call disp%skip()
52 call disp%show("getWeekNumber(-1_IK, 1_IK, 1_IK) ! The last week of 3 BC.")
53 call disp%show( getWeekNumber(-1_IK, 1_IK, 1_IK) )
54 call disp%skip()
55
56 call disp%skip()
57 call disp%show("getWeekNumber(-1_IK, 12_IK, 31_IK) ! The last week of 2 BC.")
58 call disp%show( getWeekNumber(-1_IK, 12_IK, 31_IK) )
59 call disp%skip()
60
61 call disp%skip()
62 call disp%show("getWeekNumber(0_IK, 12_IK, 31_IK) ! The last week of 1 BC.")
63 call disp%show( getWeekNumber(0_IK, 12_IK, 31_IK) )
64 call disp%skip()
65
66 call disp%skip()
67 call disp%show("getWeekNumber(1_IK, 12_IK, 31_IK) ! The first week of year 2 AD")
68 call disp%show( getWeekNumber(1_IK, 12_IK, 31_IK) )
69 call disp%skip()
70
71 call disp%skip()
72 call disp%show("getWeekNumber(1582_IK, 10_IK, 15_IK)")
73 call disp%show( getWeekNumber(1582_IK, 10_IK, 15_IK) )
74 call disp%skip()
75
76 call disp%skip()
77 call disp%show("getWeekNumber(1901_IK, 1_IK, 1_IK)")
78 call disp%show( getWeekNumber(1901_IK, 1_IK, 1_IK) )
79 call disp%skip()
80
81 call disp%skip()
82 call disp%show("getWeekNumber(1999_IK, 3_IK, 1_IK) ! 9 weeks until March 1 with majority of days in 1999.")
83 call disp%show( getWeekNumber(1999_IK, 3_IK, 1_IK) )
84 call disp%skip()
85
86 call disp%skip()
87 call disp%show("getWeekNumber(2000_IK, 3_IK, 1_IK)")
88 call disp%show( getWeekNumber(2000_IK, 3_IK, 1_IK) )
89 call disp%skip()
90
91 call disp%skip()
92 call disp%show("getWeekNumber(1999_IK, 4_IK, 15_IK)")
93 call disp%show( getWeekNumber(1999_IK, 4_IK, 15_IK) )
94 call disp%skip()
95
96 call disp%skip()
97 call disp%show("getWeekNumber(2000_IK, 4_IK, 15_IK)")
98 call disp%show( getWeekNumber(2000_IK, 4_IK, 15_IK) )
99 call disp%skip()
100
101 call disp%skip()
102 call disp%show("getWeekNumber(9999_IK, 12_IK, 31_IK)")
103 call disp%show( getWeekNumber(9999_IK, 12_IK, 31_IK) )
104 call disp%skip()
105
106end program example
Generate and return the current or the requested date and time as an integer-valued array of size 8 o...
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
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
3+2024, +8, +22, -240, +20, +23, +14, +387
5+34
6
7
8call date_and_time(values = Values)
9Values(1:3)
10+2024, +8, +22
11getWeekNumber(Values(1:3))
12+34
13
14
15getWeekNumber(+2022, +5, +8) ! Sunday: 18 weeks so far with majority of days in 2022.
16+18
17
18
19getWeekNumber(+2022, +5, +9) ! Monday: 19 weeks so far with majority of days in 2022.
20+19
21
22
23getWeekNumber(+2022, +5, +12) ! Thursday: 19 weeks so far with majority of days in 2022.
24+19
25
26
27getWeekNumber(-4713_IK, 11_IK, 24_IK)
28+48
29
30
31getWeekNumber(-1_IK, 1_IK, 1_IK) ! The last week of 3 BC.
32+53
33
34
35getWeekNumber(-1_IK, 12_IK, 31_IK) ! The last week of 2 BC.
36+52
37
38
39getWeekNumber(0_IK, 12_IK, 31_IK) ! The last week of 1 BC.
40+52
41
42
43getWeekNumber(1_IK, 12_IK, 31_IK) ! The first week of year 2 AD
44+1
45
46
47getWeekNumber(1582_IK, 10_IK, 15_IK)
48+41
49
50
51getWeekNumber(1901_IK, 1_IK, 1_IK)
52+1
53
54
55getWeekNumber(1999_IK, 3_IK, 1_IK) ! 9 weeks until March 1 with majority of days in 1999.
56+9
57
58
59getWeekNumber(2000_IK, 3_IK, 1_IK)
60+9
61
62
63getWeekNumber(1999_IK, 4_IK, 15_IK)
64+15
65
66
67getWeekNumber(2000_IK, 4_IK, 15_IK)
68+15
69
70
71getWeekNumber(9999_IK, 12_IK, 31_IK)
72+52
73
74
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 at Austin

Definition at line 3335 of file pm_dateTime.F90.


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