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

Generate and return the total number of days in the specified year or the month of the year of the Gregorian calendar. More...

Detailed Description

Generate and return the total number of days in the specified year or the month of the year of the Gregorian calendar.

The correct computation of the number of days in a year or a number of years requires taking into account the leap years.

Parameters
[in]year: The input scalar or array of the same shape as other array-like input arguments, of type integer of default kind IK, representing the year of the Gregorian Calendar.
[in]month: The input scalar or array of the same shape as other array-like input arguments, of type integer of default kind IK, representing the month of the year of the Gregorian Calendar.
(optional, if present, the number of days within the specified month of the year will be returned.)
Returns
countDays : The output scalar or array of the same shape as other array-like arguments of type integer of default kind IK, containing the number of days within the specified year (or within the specified month of the year).


Possible calling interfaces

use pm_kind, only: IK
integer(IK) :: countDaysInYear
integer(IK) :: countDaysInMonthOfYear
countDaysInYear = getCountDays(year)
countDaysInMonthOfYear = getCountDays(year, month)
Generate and return the total number of days in the specified year or the month of the year of the Gr...
This module contains classes and procedures for computing, manipulating, and styling dates and times.
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
Warning
An input argument year = 0 corresponds to the historic 1 BC notation of the Gregorian calendar.
This is in accordance with the convention in astronomical year numbering and the international standard date system, ISO 8601.
The input argument month must be a number between 1 and 12.
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.
See also
dateTimeInt_typer (class constructor)
dateTimeStr_type


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_io, only: display_type
6 use pm_dateTime, only: isLeapYear
7 use pm_dateTime, only: getMonth
8 use pm_dateTime, only: getYear
9
10 implicit none
11
12 integer(IK), allocatable :: Year(:)
13 type(display_type) :: disp
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip()
17 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
18 call disp%show("! Get the count of days in a given year of the Gregorian calendar.")
19 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
20 call disp%skip()
21
22 call disp%skip()
23 call disp%show("getYear()")
24 call disp%show( getYear() )
25 call disp%show("isLeapYear(getYear())")
26 call disp%show( isLeapYear(getYear()) )
27 call disp%show("getCountDays(getYear())")
28 call disp%show( getCountDays(getYear()) )
29 call disp%skip()
30
31 call disp%skip()
32 call disp%show("isLeapYear(2000_IK)")
33 call disp%show( isLeapYear(2000_IK) )
34 call disp%show("getCountDays(2000_IK)")
35 call disp%show( getCountDays(2000_IK) )
36 call disp%skip()
37
38 call disp%skip()
39 call disp%show("isLeapYear(2024_IK)")
40 call disp%show( isLeapYear(2024_IK) )
41 call disp%show("getCountDays(2024_IK)")
42 call disp%show( getCountDays(2024_IK) )
43 call disp%skip()
44
45 call disp%skip()
46 call disp%show("Year = [1_IK, 2_IK, 3_IK, 4_IK]")
47 Year = [1_IK, 2_IK, 3_IK, 4_IK]
48 call disp%show("Year")
49 call disp%show( Year )
50 call disp%show("isLeapYear(Year)")
51 call disp%show( isLeapYear(Year) )
52 call disp%show("getCountDays(Year)")
53 call disp%show( getCountDays(Year) )
54 call disp%skip()
55
56 call disp%skip()
57 call disp%show("Year = -[1_IK, 2_IK, 3_IK, 4_IK]")
58 Year = -[1_IK, 2_IK, 3_IK, 4_IK]
59 call disp%show("Year")
60 call disp%show( Year )
61 call disp%show("isLeapYear(Year)")
62 call disp%show( isLeapYear(Year) )
63 call disp%show("getCountDays(Year)")
64 call disp%show( getCountDays(Year) )
65 call disp%skip()
66
67 call disp%skip()
68 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
69 call disp%show("! Get the count of days in a given month of a given year of the Gregorian calendar.")
70 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
71 call disp%skip()
72
73 call disp%skip()
74 call disp%show("getYear()")
75 call disp%show( getYear() )
76 call disp%show("getMonth()")
77 call disp%show( getMonth() )
78 call disp%show("isLeapYear(getYear())")
79 call disp%show( isLeapYear(getYear()) )
80 call disp%show("getCountDays(getYear(), getMonth())")
82 call disp%skip()
83
84 call disp%skip()
85 call disp%show("isLeapYear(2000_IK)")
86 call disp%show( isLeapYear(2000_IK) )
87 call disp%show("getCountDays(2000_IK, 2_IK)")
88 call disp%show( getCountDays(2000_IK, 2_IK) )
89 call disp%skip()
90
91 call disp%skip()
92 call disp%show("isLeapYear(2024_IK)")
93 call disp%show( isLeapYear(2024_IK) )
94 call disp%show("getCountDays(2024_IK, 2_IK)")
95 call disp%show( getCountDays(2024_IK, 2_IK) )
96 call disp%skip()
97
98 call disp%skip()
99 call disp%show("Year = [1_IK, 2_IK, 3_IK, 4_IK]")
100 Year = [1_IK, 2_IK, 3_IK, 4_IK]
101 call disp%show("Year")
102 call disp%show( Year )
103 call disp%show("isLeapYear(Year)")
104 call disp%show( isLeapYear(Year) )
105 call disp%show("getCountDays(Year, 2_IK)")
106 call disp%show( getCountDays(Year, 2_IK) )
107 call disp%skip()
108
109 call disp%skip()
110 call disp%show("Year = -[1_IK, 2_IK, 3_IK, 4_IK]")
111 Year = -[1_IK, 2_IK, 3_IK, 4_IK]
112 call disp%show("Year")
113 call disp%show( Year )
114 call disp%show("isLeapYear(Year)")
115 call disp%show( isLeapYear(Year) )
116 call disp%show("getCountDays(Year, 2_IK)")
117 call disp%show( getCountDays(Year, 2_IK) )
118 call disp%skip()
119
120end 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
integer(IK) function getYear()
Generate and return the current year of the Gregorian calendar.
pure elemental logical(LK) function isLeapYear(year)
Generate and return .true. if the input year is a leap year.
integer(IK) function getMonth()
Generate and return the current month of the Gregorian calendar.
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
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 count of days in a given year of the Gregorian calendar.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
8+2024
10T
12+366
13
14
15isLeapYear(2000_IK)
16T
17getCountDays(2000_IK)
18+366
19
20
21isLeapYear(2024_IK)
22T
23getCountDays(2024_IK)
24+366
25
26
27Year = [1_IK, 2_IK, 3_IK, 4_IK]
28Year
29+1, +2, +3, +4
30isLeapYear(Year)
31F, F, F, T
32getCountDays(Year)
33+365, +365, +365, +366
34
35
36Year = -[1_IK, 2_IK, 3_IK, 4_IK]
37Year
38-1, -2, -3, -4
39isLeapYear(Year)
40F, F, F, T
41getCountDays(Year)
42+365, +365, +365, +366
43
44
45!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46! Get the count of days in a given month of a given year of the Gregorian calendar.
47!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
49
50getYear()
51+2024
53+10
55T
57+31
58
59
60isLeapYear(2000_IK)
61T
62getCountDays(2000_IK, 2_IK)
63+29
64
65
66isLeapYear(2024_IK)
67T
68getCountDays(2024_IK, 2_IK)
69+29
70
71
72Year = [1_IK, 2_IK, 3_IK, 4_IK]
73Year
74+1, +2, +3, +4
75isLeapYear(Year)
76F, F, F, T
77getCountDays(Year, 2_IK)
78+28, +28, +28, +29
79
80
81Year = -[1_IK, 2_IK, 3_IK, 4_IK]
82Year
83-1, -2, -3, -4
84isLeapYear(Year)
85F, F, F, T
86getCountDays(Year, 2_IK)
87+28, +28, +28, +29
88
89
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 3628 of file pm_dateTime.F90.


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