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

Generate and return the calendarical difference in days between the two input Gregorian dates octuples (Values1(:) - Values2(:)). More...

Detailed Description

Generate and return the calendarical difference in days between the two input Gregorian dates octuples (Values1(:) - Values2(:)).

This algorithm carefully takes into account the possibility of leap years and different time zones.
If Values1 is smaller than Values2 the difference between the two dates is negative.

Parameters
[in]Values1: The input contiguous vector of size 8 of type integer of default kind IK, containing the octuple [year, month, day, zone, hour, minute, seconds, milliseconds] of the Gregorian calendar from which Values2 should be subtracted.
The order of the elements of the vector follows that of the values returned by the Fortran intrinsic date_and_time().
[in]Values2: The input contiguous vector of size 8 of type integer of default kind IK, containing the octuple [year, month, day, zone, hour, minute, seconds, milliseconds] of the Gregorian calendar that should be subtracted from Values1.
The order of the elements of the vector follows that of the values returned by the Fortran intrinsic date_and_time().
Returns
dateTimeDiff : The output scalar of type real of default kind RK containing the result (in units of days, possible fractional) of the subtraction of Values2 date octuple from Values1 date octuple (Values1 - Values2).


Possible calling interfaces

use pm_kind, only: IK, RK
integer(IK) :: Values1(8)
integer(IK) :: Values2(8)
real(RK) :: dateTimeDiff
dateTimeDiff = getDateTimeDiff(Values1(1:8), Values2(1:8)) ! return Values1 - Values2 in units of days.
!
Generate and return the calendarical difference in days between the two input Gregorian dates octuple...
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 RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
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
The sizes of the two input vector arguments must be the same and equal to 8.
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.
Remarks
The procedures under this generic interface are always impure when all input arguments are missing.
See also
getJulianDay
getDateTimeShifted


Example usage

1program example
2
3 use pm_kind, only: IK, RK, SK
4 use pm_io, only: display_type
5 use pm_dateTime, only: getDateTime
9
10 implicit none
11
12 type(display_type) :: disp
13 disp = display_type(file = "main.out.F90")
14
15 call disp%skip()
16 call disp%show("getDateTimeUTC()")
17 call disp%show( getDateTimeUTC() )
18 call disp%show("getDateTime(2000_IK)")
19 call disp%show( getDateTime(2000_IK) )
20 call disp%show("getDateTimeDiff(getDateTime(), getDateTime(2000_IK))")
22 call disp%show("getDateTimeDiff(getDateTime(), getDateTimeShifted(-1.5_RK))")
24
25 call disp%skip()
26 call disp%show("getDateTime(1999_IK, 2_IK, 28_IK)")
27 call disp%show( getDateTime(1999_IK, 2_IK, 28_IK) )
28 call disp%show("getDateTime(1999_IK, 3_IK, 1_IK)")
29 call disp%show( getDateTime(1999_IK, 3_IK, 1_IK) )
30 call disp%show("getDateTimeDiff(getDateTime(1999_IK, 3_IK, 1_IK), getDateTime(1999_IK, 2_IK, 28_IK)) ! year 1999 is not a leap year.")
31 call disp%show( getDateTimeDiff(getDateTime(1999_IK, 3_IK, 1_IK), getDateTime(1999_IK, 2_IK, 28_IK)) )
32
33 call disp%skip()
34 call disp%show("getDateTime(2000_IK, 2_IK, 28_IK)")
35 call disp%show( getDateTime(2000_IK, 2_IK, 28_IK) )
36 call disp%show("getDateTime(2000_IK, 3_IK, 1_IK)")
37 call disp%show( getDateTime(2000_IK, 3_IK, 1_IK) )
38 call disp%show("getDateTimeDiff(getDateTime(2000_IK, 3_IK, 1_IK), getDateTime(2000_IK, 2_IK, 28_IK)) ! year 2000 is a leap year.")
39 call disp%show( getDateTimeDiff(getDateTime(2000_IK, 3_IK, 1_IK), getDateTime(2000_IK, 2_IK, 28_IK)) )
40
41 call disp%skip()
42 call disp%show("getDateTime(2019_IK, 1_IK, 1_IK)")
43 call disp%show( getDateTime(2019_IK, 1_IK, 1_IK) )
44 call disp%show("getDateTime(2019_IK, 12_IK, 31_IK)")
45 call disp%show( getDateTime(2019_IK, 12_IK, 31_IK) )
46 call disp%show("getDateTimeDiff(getDateTime(2019_IK, 1_IK, 1_IK), getDateTime(2019_IK, 12_IK, 31_IK)) ! year 2019 is not a leap year.")
47 call disp%show( getDateTimeDiff(getDateTime(2019_IK, 1_IK, 1_IK), getDateTime(2019_IK, 12_IK, 31_IK)) )
48
49 call disp%skip()
50 call disp%show("getDateTime(2020_IK, 1_IK, 1_IK)")
51 call disp%show( getDateTime(2020_IK, 1_IK, 1_IK) )
52 call disp%show("getDateTime(2020_IK, 12_IK, 31_IK)")
53 call disp%show( getDateTime(2020_IK, 12_IK, 31_IK) )
54 call disp%show("getDateTimeDiff(getDateTime(2020_IK, 1_IK, 1_IK), getDateTime(2020_IK, 12_IK, 31_IK)) ! year 2020 is a leap year.")
55 call disp%show( getDateTimeDiff(getDateTime(2020_IK, 1_IK, 1_IK), getDateTime(2020_IK, 12_IK, 31_IK)) )
56
57 call disp%skip()
58 call disp%show("getDateTime(2020_IK, 1_IK, 1_IK)")
59 call disp%show( getDateTime(2020_IK, 1_IK, 1_IK) )
60 call disp%show("getDateTime(2021_IK, 1_IK, 1_IK)")
61 call disp%show( getDateTime(2021_IK, 1_IK, 1_IK) )
62 call disp%show("getDateTimeDiff(getDateTime(2020_IK, 1_IK, 1_IK), getDateTime(2021_IK, 1_IK, 1_IK)) ! year 2020 is a leap year.")
63 call disp%show( getDateTimeDiff(getDateTime(2020_IK, 1_IK, 1_IK), getDateTime(2021_IK, 1_IK, 1_IK)) )
64
65 call disp%skip()
66 call disp%show("getDateTime(1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK)")
67 call disp%show( getDateTime(1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK) )
68 call disp%show("getDateTime(1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK)")
69 call disp%show( getDateTime(1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK) )
70 call disp%show("getDateTimeDiff(getDateTime(1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK), getDateTime(1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK))")
71 call disp%show( getDateTimeDiff(getDateTime(1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK), getDateTime(1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK)) )
72
73 call disp%skip()
74 call disp%show("getDateTime(-1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK)")
75 call disp%show( getDateTime(-1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK) )
76 call disp%show("getDateTime(-1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK)")
77 call disp%show( getDateTime(-1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK) )
78 call disp%show("getDateTimeDiff(getDateTime(-1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK), getDateTime(-1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK))")
79 call disp%show( getDateTimeDiff(getDateTime(-1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK), getDateTime(-1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK)) )
80
81end program example
Generate and return the current or the requested Gregorian date and time shifted by the specified amo...
Generate and return the current or the requested date and time converted to the corresponding Coordin...
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
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, +23, +0, +0, +23, +3, +783
4getDateTime(2000_IK)
5+2000, +1, +1, +0, +0, +0, +0, +0
7+9001.0160160069354
9+1.5000000000000000
10
11getDateTime(1999_IK, 2_IK, 28_IK)
12+1999, +2, +28, +0, +0, +0, +0, +0
13getDateTime(1999_IK, 3_IK, 1_IK)
14+1999, +3, +1, +0, +0, +0, +0, +0
15getDateTimeDiff(getDateTime(1999_IK, 3_IK, 1_IK), getDateTime(1999_IK, 2_IK, 28_IK)) ! year 1999 is not a leap year.
16+1.0000000000000000
17
18getDateTime(2000_IK, 2_IK, 28_IK)
19+2000, +2, +28, +0, +0, +0, +0, +0
20getDateTime(2000_IK, 3_IK, 1_IK)
21+2000, +3, +1, +0, +0, +0, +0, +0
22getDateTimeDiff(getDateTime(2000_IK, 3_IK, 1_IK), getDateTime(2000_IK, 2_IK, 28_IK)) ! year 2000 is a leap year.
23+2.0000000000000000
24
25getDateTime(2019_IK, 1_IK, 1_IK)
26+2019, +1, +1, +0, +0, +0, +0, +0
27getDateTime(2019_IK, 12_IK, 31_IK)
28+2019, +12, +31, +0, +0, +0, +0, +0
29getDateTimeDiff(getDateTime(2019_IK, 1_IK, 1_IK), getDateTime(2019_IK, 12_IK, 31_IK)) ! year 2019 is not a leap year.
30-364.00000000000000
31
32getDateTime(2020_IK, 1_IK, 1_IK)
33+2020, +1, +1, +0, +0, +0, +0, +0
34getDateTime(2020_IK, 12_IK, 31_IK)
35+2020, +12, +31, +0, +0, +0, +0, +0
36getDateTimeDiff(getDateTime(2020_IK, 1_IK, 1_IK), getDateTime(2020_IK, 12_IK, 31_IK)) ! year 2020 is a leap year.
37-365.00000000000000
38
39getDateTime(2020_IK, 1_IK, 1_IK)
40+2020, +1, +1, +0, +0, +0, +0, +0
41getDateTime(2021_IK, 1_IK, 1_IK)
42+2021, +1, +1, +0, +0, +0, +0, +0
43getDateTimeDiff(getDateTime(2020_IK, 1_IK, 1_IK), getDateTime(2021_IK, 1_IK, 1_IK)) ! year 2020 is a leap year.
44-366.00000000000000
45
46getDateTime(1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK)
47+1, +1, +1, +720, +0, +0, +0, +0
48getDateTime(1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK)
49+1, +1, +1, -720, +0, +0, +0, +0
50getDateTimeDiff(getDateTime(1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK), getDateTime(1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK))
51-1.0000000000000000
52
53getDateTime(-1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK)
54-1, +1, +1, +720, +0, +0, +0, +0
55getDateTime(-1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK)
56-1, +1, +1, -720, +0, +0, +0, +0
57getDateTimeDiff(getDateTime(-1_IK, 1_IK, 1_IK, zone = -12_IK * 60_IK), getDateTime(-1_IK, 1_IK, 1_IK, zone = +12_IK * 60_IK))
58+1.0000000000000000
59
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, 3:59 AM, National Institute for Fusion Studies, The University of Texas at Austin

Definition at line 1811 of file pm_dateTime.F90.


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