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

Generate and return .true. if the input date and time values(:) or (year, month, day, zone, hour, second, millisecond) octuple corresponds to a valid Gregorian Calendar date and time. More...

Detailed Description

Generate and return .true. if the input date and time values(:) or (year, month, day, zone, hour, second, millisecond) octuple corresponds to a valid Gregorian Calendar date and time.

Returning the correct result requires taking into account the possibility of leap years and the varying day counts of months.
A valid date requires,

  1. a month between 1 and 12,
  2. a day between 1 and 31 and consistent with the specified month and year,
  3. a zone must be between -12:00 and +14:00 UTC, corresponding to -720 and +840 minutes as used here.
  4. an hour of day between 0 and 23,
  5. a minute of hour between 0 and 59,
  6. a second of minute between 0 and 59,
  7. a millisecond of second between 0 and 999.
Parameters
[in]values: The input contiguous array of shape (:) of type integer of default kind IK, containing the octuple [year, month, day, zone, hour, minute, second, millisecond] or a subset of it that always starts with year representing a Gregorian calendar date and/or time.
The order of the elements of values follows that of the values argument of the Fortran intrinsic date_and_time().
(optional. It must 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 a year of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present 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 a month of a year of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present 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 a day of a month of a year of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present only if the input argument month is present.)
[in]zone: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing a time zone of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present only if the input argument day is present.)
[in]hour: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing the hour of a day of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present only if the input argument zone is present.)
[in]minute: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing the minute of the hour of a day of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present only if the input argument hour is present.)
[in]second: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing the second of the minute of the hour of a day of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present only if the input argument minute is present.)
[in]millisecond: The input scalar, or array of the same shape as other array-like arguments, of type integer of default kind IK, containing the millisecond of the second of the minute of the hour of a day of the Gregorian calendar.
(optional, default = any value that yields a valid date given the other input argument. It can be present only if the input argument second is present.)
Returns
isValid : The output scalar or array of the same shape as the input array-like arguments (except Vector), of type logical of default kind LK. It is .true. if and only if the input argument(s) correspond to a valid date and/or month of the Gregorian Calendar.
Otherwise, it is .false. is the input date and time is invalid or if the condition 0 < size(values) < 9 does not hold.


Possible calling interfaces

logical(LK) :: isValid
isValid = isValidDateTime(year) ! elemental
isValid = isValidDateTime(year, month) ! elemental
isValid = isValidDateTime(year, month, day) ! elemental
isValid = isValidDateTime(year, month, day, zone) ! elemental
isValid = isValidDateTime(year, month, day, zone, hour) ! elemental
isValid = isValidDateTime(year, month, day, zone, hour, minute) ! elemental
isValid = isValidDateTime(year, month, day, zone, hour, minute, second) ! elemental
isValid = isValidDateTime(year, month, day, zone, hour, minute, second, millisecond) ! elemental
isValid = isValidDateTime(values(1:1)) ! values = [year]
isValid = isValidDateTime(values(1:2)) ! values = [year, month]
isValid = isValidDateTime(values(1:3)) ! values = [year, month, day]
isValid = isValidDateTime(values(1:4)) ! values = [year, month, day, zone]
isValid = isValidDateTime(values(1:5)) ! values = [year, month, day, zone, hour]
isValid = isValidDateTime(values(1:6)) ! values = [year, month, day, zone, hour, minute]
isValid = isValidDateTime(values(1:7)) ! values = [year, month, day, zone, hour, minute, second]
isValid = isValidDateTime(values(1:8)) ! values = [year, month, day, zone, hour, minute, second, millisecond]
!
Generate and return .true. if the input date and time values(:) or (year, month, day,...
This module contains classes and procedures for computing, manipulating, and styling dates and times.
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.
In these systems, the year 0 is a leap year.
The size of the input argument values(:) must be non-zero and less than 8, otherwise, the returned value is .false..
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
getDateAfter
getDateTime


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_io, only: display_type
6
7 implicit none
8
9 integer :: i
10 integer(IK) :: Values(9)
11
12 type(display_type) :: disp
13 disp = display_type(file = "main.out.F90")
14
15 call disp%skip()
16 call disp%show("isValidDateTime(0_IK)")
17 call disp%show( isValidDateTime(0_IK) )
18 call disp%skip()
19
20 call disp%skip()
21 call disp%show("getYear()")
22 call disp%show( getYear() )
23 call disp%show("isValidDateTime(getYear())")
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("Values(1:8)")
31 call disp%show( Values(1:8) )
32 call disp%skip()
33 do i = size(Values), 0, -1
34 call disp%show("i")
35 call disp%show( i )
36 call disp%show("isValidDateTime(Values(1:i))")
37 call disp%show( isValidDateTime(Values(1:i)) )
38 call disp%skip()
39 end do
40 call disp%skip()
41
42 call disp%skip()
43 call disp%show("isValidDateTime(1999_IK, 2_IK, 28_IK) ! February is 28 days in non-leap years.")
44 call disp%show( isValidDateTime(1999_IK, 2_IK, 28_IK) )
45 call disp%show("isValidDateTime(1999_IK, 2_IK, 29_IK) ! February is 28 days in non-leap years.")
46 call disp%show( isValidDateTime(1999_IK, 2_IK, 29_IK) )
47 call disp%skip()
48
49 call disp%skip()
50 call disp%show("isValidDateTime(2000_IK, 2_IK, 28_IK) ! February is 29 days in leap years.")
51 call disp%show( isValidDateTime(2000_IK, 2_IK, 28_IK) )
52 call disp%show("isValidDateTime(2000_IK, 2_IK, 29_IK) ! February is 29 days in leap years.")
53 call disp%show( isValidDateTime(2000_IK, 2_IK, 29_IK) )
54 call disp%skip()
55
56end 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.
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
3T
4
5
7+2024
9T
10
11
12call date_and_time(values = Values(1:8))
13Values(1:8)
14+2024, +10, +27, -300, +22, +32, +41, +928
15
16i
17+9
18isValidDateTime(Values(1:i))
19F
20
21i
22+8
23isValidDateTime(Values(1:i))
24T
25
26i
27+7
28isValidDateTime(Values(1:i))
29T
30
31i
32+6
33isValidDateTime(Values(1:i))
34T
35
36i
37+5
38isValidDateTime(Values(1:i))
39T
40
41i
42+4
43isValidDateTime(Values(1:i))
44T
45
46i
47+3
48isValidDateTime(Values(1:i))
49T
50
51i
52+2
53isValidDateTime(Values(1:i))
54T
55
56i
57+1
58isValidDateTime(Values(1:i))
59T
60
61i
62+0
63isValidDateTime(Values(1:i))
64F
65
66
67
68isValidDateTime(1999_IK, 2_IK, 28_IK) ! February is 28 days in non-leap years.
69T
70isValidDateTime(1999_IK, 2_IK, 29_IK) ! February is 28 days in non-leap years.
71F
72
73
74isValidDateTime(2000_IK, 2_IK, 28_IK) ! February is 29 days in leap years.
75T
76isValidDateTime(2000_IK, 2_IK, 29_IK) ! February is 29 days in leap years.
77T
78
79
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 2795 of file pm_dateTime.F90.


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