Generate and return the current or the requested Gregorian date and time shifted by the specified amount
in units of days.
More...
Generate and return the current or the requested Gregorian date and time shifted by the specified amount
in units of days.
This algorithm carefully takes into account the possibility of leap years.
If the input amount
is in units other than days, such as hours, minutes or seconds, simply use the relevant module constants (e.g., MINUTES_PER_DAY or SECONDS_PER_DAY) to convert the non-day measures of time to days.
- Parameters
-
[in] | amount | : The input scalar of type real of default kind RK, containing the number of days (possibly fractional) with which the input date and time must be shifted.
It can practically be any positive or negative value. Note that a day is 86400 seconds (SECONDS_PER_DAY).
|
[in] | year | : The input scalar of type integer of default kind IK, containing the year of the Gregorian calendar.
(optional, default = the current value if all input arguments except amount are missing. It can be present only if values is missing.) |
[in] | month | : The input scalar of type integer of default kind IK, containing the month of the year of the Gregorian calendar.
(optional, default = 1 (or the current value if all input arguments are missing). It can be present only if year is also present.) |
[in] | day | : The input scalar of type integer of default kind IK, containing the day of the month of the year of the Gregorian calendar.
(optional, default = 1 . (or the current value if all input arguments are missing). It can be present only if month is also present.) |
[in] | zone | : The input scalar of type integer of default kind IK, containing the local time zone of the Gregorian calendar in minutes.
The input argument zone has no effects on the output shifted date and time. It is only used to construct the output date and time vector.
(optional, default = 0 (UTC) (or the current value if all input arguments are missing). It can be present only if day is also present.) |
[in] | hour | : The input scalar of type integer of default kind IK, containing the hour of the day of the Gregorian calendar.
(optional, default = 0 (or the current value if all input arguments are missing). It can be present only if zone is present.) |
[in] | minute | : The input scalar of type integer of default kind IK, containing the minute of the hour of the day of the Gregorian calendar.
(optional, default = 0 (or the current value if all input arguments are missing). It can be present only if hour is present.) |
[in] | second | : The input scalar of type integer of default kind IK, containing the second of the minute of the hour of the day of the Gregorian calendar.
(optional, default = 0 (or the current value if all input arguments are missing). It can be present only if minute is present.) |
[in] | millisecond | : The input scalar of type integer of default kind IK, containing the millisecond of the second of the minute of the hour of the day of the Gregorian calendar.
(optional, default = 0 (or the current value if all input arguments are missing). It can be present only if second is present.) |
[in] | values | : The input contiguous vector of minimum size 1 and maximum size 8 of type integer of default kind IK, containing the values [year, month, day, zone, hour, minute, seconds, milliseconds] of the Gregorian calendar or a subset of the octuple starting with year .
The order of the elements of the vector follows that of the values returned by the Fortran intrinsic date_and_time() .
(optional, default = the current date and time. It can be present only if all other arguments except amount are missing.) |
- Returns
dateTimeShifted(1:8)
: The output vector of size 8
of type integer
of default kind IK containing the requested local date and time of the Gregorian Calendar corresponding to the input date and time shifted by the specified amount
in the order [year, month, day, zone, hour, minute, seconds, milliseconds]
. By definition, dateTimeShifted(4)
(corresponding to the local time zone) is the same as values(4)
or the zone
input argument.
Possible calling interfaces ⛓
integer(IK) :: values(8)
integer(IK) :: dateTimeShifted(8)
dateTimeShifted(
1:
8)
= getDateTimeShifted(amount, year, month, day, zone, hour, minute, second)
dateTimeShifted(
1:
8)
= getDateTimeShifted(amount, year, month, day, zone, hour, minute, second, millisecond)
!
Generate and return the current or the requested Gregorian date and time shifted by the specified amo...
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...
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
- Warning
- The input
month
must be a number between 1
and 12
.
The input day
must be a number between 1
and 31
and be consistent with the specified month and (leap) year.
The input zone
must be a valid time zone in units of minutes.
The input hour
must be a number between 0
and 23
.
The input minute
must be a number between 0
and 59
.
The input second
must be a number between 0
and 59
.
The input millisecond
must be a number between 0
and 999
.
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.
- See also
- getJulianDay
getDateTimeDiff
Example usage ⛓
18 type(display_type) :: disp
24 call disp%show(
"getDateTimeShifted(1._RK)")
26 call disp%show(
"getDateTimeShifted(1._RK, getDateTime())")
30 call disp%show(
"getDateTimeShifted(2._RK, 2000_IK)")
34 call disp%show(
"getDateTimeShifted(3._RK, 2000_IK, 1_IK)")
38 call disp%show(
"getDateTimeShifted(300._RK, 2000_IK, 1_IK, 1_IK)")
42 call disp%show(
"getDateTimeShifted(366._RK, 2000_IK, 1_IK, 1_IK, getZone())")
46 call disp%show(
"getDateTimeShifted(-366._RK, 2000_IK, 1_IK, 1_IK, getZone())")
50 call disp%show(
"getDateTimeShifted(-366.25_RK, 2000_IK, 1_IK, 1_IK, 0_IK)")
54 call disp%show(
"getDateTimeShifted(1._RK, getYear(), getMonth(), getDay(), getZone(), getHour())")
58 call disp%show(
"getDateTimeShifted(1._RK, getYear(), getMonth(), getDay(), getZone(), getHour(), getMinute())")
62 call disp%show(
"getDateTimeShifted(1._RK, getYear(), getMonth(), getDay(), getZone(), getHour(), getMinute(), getSecond())")
66 call disp%show(
"getDateTimeShifted(1._RK, getYear(), getMonth(), getDay(), getZone(), getHour(), getMinute(), getSecond(), getMillisecond())")
70 call disp%show(
"getDateTimeShifted(-1._RK, 2000_IK, 12_IK, 31_IK, -660_IK)")
74 call disp%show(
"getDateTimeShifted(0._RK, 2000_IK, 12_IK, 31_IK, -660_IK)")
78 call disp%show(
"getDateTimeShifted(2*365._RK, 2000_IK, 12_IK, 31_IK, -660_IK)")
83 call disp%show(
"getDateTimeShifted(-2*365._RK, 2000_IK, 12_IK, 31_IK, -660_IK, 18_IK)")
87 call disp%show(
"getDateTimeShifted(0._RK, 2000_IK, 12_IK, 31_IK, -660_IK, 18_IK)")
91 call disp%show(
"getDateTimeShifted(+2*365._RK, 2000_IK, 12_IK, 31_IK, -660_IK, 18_IK)")
96 call disp%show(
"getDateTimeShifted(300._RK, 2000_IK, 12_IK, 31_IK, -660_IK, 18_IK, 21_IK)")
100 call disp%show(
"getDateTimeShifted(313._RK, 2000_IK, 12_IK, 31_IK, -660_IK, 18_IK, 21_IK)")
104 call disp%show(
"getDateTimeShifted(300._RK, 2000_IK, 12_IK, 31_IK, -660_IK, 18_IK, 21_IK, 35_IK)")
108 call disp%show(
"getDateTimeShifted(300._RK, 2000_IK, 12_IK, 31_IK, -660_IK, 18_IK, 21_IK, 35_IK, 847_IK)")
112 call disp%show(
"getDateTimeShifted(300._RK, 2000_IK, 2_IK, 29_IK, -660_IK, 18_IK, 21_IK, 35_IK, 847_IK)")
116 call disp%show(
"getDateTimeShifted(-300._RK, 2000_IK, 3_IK, 1_IK, +660_IK, 8_IK, 21_IK, 35_IK, 847_IK)")
120 call disp%show(
"getDateTimeShifted(-100._RK, 1999_IK, 3_IK, 1_IK, +660_IK, 8_IK, 21_IK, 35_IK, 847_IK)")
124 call disp%show(
"getDateTimeShifted(365._RK, 1999_IK, 1_IK, 1_IK, +660_IK, 0_IK, 0_IK, 0_IK, 0_IK)")
128 call disp%show(
"getDateTimeShifted(365._RK, 1999_IK, 1_IK, 1_IK, +660_IK)")
132 call disp%show(
"getDateTimeShifted(365._RK, 1999_IK, 1_IK, 1_IK)")
136 call disp%show(
"getDateTimeShifted(365._RK, 1999_IK, 1_IK)")
140 call disp%show(
"getDateTimeShifted(365._RK, 1999_IK)")
144 call disp%show(
"getDateTimeShifted(365._RK, 2000_IK)")
148 call disp%show(
"getDateTimeShifted(366._RK, 2000_IK)")
152 call disp%show(
"getDateTimeShifted(-366._RK, 2000_IK, 12_IK, 31_IK)")
156 call disp%show(
"getDateTimeShifted(2.5_RK, -1_IK, 12_IK, 31_IK, -660_IK, 20_IK)")
160 call disp%show(
"getDateTimeShifted(-1.2_RK, 1_IK, 1_IK, 1_IK, +660_IK)")
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.
This is a generic method of the derived type display_type with pass attribute.
integer(IK) function getYear()
Generate and return the current year of the Gregorian calendar.
integer(IK) function getZone()
Generate and return the local time difference in minutes with respect to the Coordinated Universal Ti...
integer(IK) function getMinute()
Generate and return the current minute of the local hour of the current day of the Gregorian calendar...
integer(IK) function getMillisecond()
Generate and return the current millisecond of the current second of the current minute of the local ...
impure elemental integer(IKG) function getHour(zone)
Generate and return the current local hour of the current day of the Gregorian calendar,...
integer(IK) function getSecond()
Generate and return the current second of the current minute of the local hour of the current day of ...
integer(IK) function getMonth()
Generate and return the current month of the Gregorian calendar.
integer(IK) function getDay()
Generate and return the current day of the Gregorian calendar.
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
3+2024,
+11,
+14,
-360,
+22,
+14,
+23,
+835
5+2024,
+11,
+15,
-360,
+22,
+14,
+23,
+835
7+2024,
+11,
+15,
-360,
+22,
+14,
+23,
+835
10+2000,
+1,
+3,
+0,
+0,
+0,
+0,
+0
13+2000,
+1,
+4,
+0,
+0,
+0,
+0,
+0
16+2000,
+10,
+27,
+0,
+0,
+0,
+0,
+0
19+2001,
+1,
+1,
-360,
+0,
+0,
+0,
+0
22+1998,
+12,
+31,
-360,
+0,
+0,
+0,
+0
25+1998,
+12,
+30,
+0,
+18,
+0,
+0,
+0
28+2024,
+11,
+15,
-360,
+22,
+0,
+0,
+0
31+2024,
+11,
+15,
-360,
+22,
+14,
+0,
+0
34+2024,
+11,
+15,
-360,
+22,
+14,
+23,
+0
37+2024,
+11,
+15,
-360,
+22,
+14,
+23,
+835
40+2000,
+12,
+30,
-660,
+0,
+0,
+0,
+0
43+2000,
+12,
+31,
-660,
+0,
+0,
+0,
+0
46+2002,
+12,
+31,
-660,
+0,
+0,
+0,
+0
50+1999,
+1,
+1,
-660,
+18,
+0,
+0,
+0
53+2000,
+12,
+31,
-660,
+18,
+0,
+0,
+0
56+2002,
+12,
+31,
-660,
+18,
+0,
+0,
+0
60+2001,
+10,
+27,
-660,
+18,
+21,
+0,
+0
63+2001,
+11,
+9,
-660,
+18,
+21,
+0,
+0
66+2001,
+10,
+27,
-660,
+18,
+21,
+35,
+0
68getDateTimeShifted(
300._RK,
2000_IK,
12_IK,
31_IK,
-660_IK,
18_IK,
21_IK,
35_IK,
847_IK)
69+2001,
+10,
+27,
-660,
+18,
+21,
+35,
+847
72+2000,
+12,
+25,
-660,
+18,
+21,
+35,
+847
75+1999,
+5,
+6,
+660,
+8,
+21,
+35,
+847
78+1998,
+11,
+21,
+660,
+8,
+21,
+35,
+847
81+2000,
+1,
+1,
+660,
+0,
+0,
+0,
+0
84+2000,
+1,
+1,
+660,
+0,
+0,
+0,
+0
87+2000,
+1,
+1,
+0,
+0,
+0,
+0,
+0
90+2000,
+1,
+1,
+0,
+0,
+0,
+0,
+0
93+2000,
+1,
+1,
+0,
+0,
+0,
+0,
+0
96+2000,
+12,
+31,
+0,
+0,
+0,
+0,
+0
99+2001,
+1,
+1,
+0,
+0,
+0,
+0,
+0
102+1999,
+12,
+31,
+0,
+0,
+0,
+0,
+0
105+0,
+1,
+3,
-660,
+8,
+0,
+0,
+0
108+0,
+12,
+30,
+660,
+19,
+12,
+0,
+0
- 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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, March 22, 2012, 3:59 AM, National Institute for Fusion Studies, The University of Texas Austin
Definition at line 1652 of file pm_dateTime.F90.