qtDateTime
|
Overview
The MODULE qtDateTime supplies TYPEs, FUNCTIONs, and SUBROUTINEs for date and time calculations.
The date calculations are based on the Gregorian calendar (enacted in 1582).
More...
Data Types | |
interface | assignment(=) |
interface | operator(+) |
interface | operator(-) |
interface | operator(.eq.) |
interface | operator(.ge.) |
interface | operator(.gt.) |
interface | operator(.le.) |
interface | operator(.lt.) |
interface | operator(.ne.) |
interface | qtdt_f_cumulateddays |
interface | qtdt_f_daysinmonth |
interface | qtdt_f_daysinyear |
interface | qtdt_f_leapyear |
interface | qtdt_f_millisecondstodaytime |
interface | qtdt_f_millisecondstotime |
type | qtdt_t_date |
type | qtdt_t_daytime |
type | qtdt_t_time |
type | qtdt_t_timestamp |
Public Member Functions | |
subroutine | qtdt_s_initialization (cLicenceNumber) |
qtDT_S_InitializationInitializes qtDateTime More... | |
type(qtdt_t_date) function | qtdt_f_datetoday () |
qtDT_F_DateTodayReturns today's date More... | |
integer(qtdt_k_int4) function | qtdt_f_datetointeger (tDate) |
qtDT_F_DateToIntegerConverts a date into an integer value. More... | |
subroutine | qtdt_s_int4arraytodate (tDate, iaDate) |
qtDT_S_IntegerArrayToDateConverts a date specification in an array into a date type. More... | |
subroutine | qtdt_s_int2arraytodate (tDate, iaDate) |
subroutine | qtdt_s_datetoint4array (iaDate, tDate) |
qtDT_S_DateToIntegerArrayConverts a date specification in an array into a date type. More... | |
subroutine | qtdt_s_datetoint2array (iaDate, tDate) |
logical function | qtdt_f_isvaliddate (tDate) |
qtDT_F_IsValidDateChecks if the date value is valid More... | |
logical function | qtdt_f_dateeq (tDate1, tDate2) |
qtDT_F_DateEQCompares if two dates are equal. More... | |
logical function | qtdt_f_datene (tDate1, tDate2) |
qtDT_F_DateNECompares if two dates are not equal. More... | |
logical function | qtdt_f_dategt (tDate1, tDate2) |
qtDT_F_DateGTChecks if a date is greater than another. More... | |
logical function | qtdt_f_datege (tDate1, tDate2) |
qtDT_F_DateGEChecks for a date being greater than another or equal to it. More... | |
logical function | qtdt_f_datelt (tDate1, tDate2) |
qtDT_F_DateLTChecks if a date is lower than another. More... | |
logical function | qtdt_f_datele (tDate1, tDate2) |
qtDT_F_DateLEChecks for a date being lower than another or equal to it. More... | |
integer function | qtdt_f_leapyeari (iYear) |
qtDT_F_LeapYearChecks, if a year is a leap-year. More... | |
integer function | qtdt_f_leapyeart (tDate) |
qtDT_F_LeapYearChecks, if a year is a leap-year. More... | |
integer function | qtdt_f_daysinyeari (iYear) |
qtDT_F_DaysInYearReturns the number of days in a year More... | |
integer function | qtdt_f_daysinyeart (tDate) |
qtDT_F_DaysInYearReturns the number of days in a year More... | |
integer function | qtdt_f_daysinmonth4 (iMonth, iYear) |
qtDT_F_DaysInMonthReturns the number of days of a month for the specified year More... | |
integer function | qtdt_f_daysinmonth2 (iMonth, iYear) |
qtDT_F_DaysInMonthReturns the number of days of a month for the specified year More... | |
integer function | qtdt_f_daysinmontht (tDate) |
qtDT_F_DaysInMonthReturns the number of days of a month for the specified date More... | |
integer function | qtdt_f_cumulateddaysi4 (iMonth, iYear) |
qtDT_F_CumulatedDaysReturns the cumulated number of days in the months of a year before the given month More... | |
integer function | qtdt_f_cumulateddaysi2 (iMonth, iYear) |
integer(qtdt_k_int2) function | qtdt_f_dayofyear (tDate) |
qtDT_F_DayOfYearReturns the day of year (1 - 365|366) for a given date. More... | |
type(qtdt_t_date) function | qtdt_f_dayofyeartodate (iDoY, iYear) |
qtDT_F_DayOfYearToDateDetermines the date for a given day of year (1 - 365|366). More... | |
integer(qtdt_k_int4) function | qtdt_f_datedifference (tDate2, tDate1) |
qtDT_F_DateDifferenceReturns the difference of two dates in days More... | |
type(qtdt_t_date) function | qtdt_f_dateadddays (tDateS, nDays) |
qtDT_F_DateAddDaysReturns a date that is the result of adding days to a given date More... | |
type(qtdt_t_date) function | qtdt_f_dateadddays2 (nDays, tDateS) |
type(qtdt_t_date) function | qtdt_f_datesubdays (tDateS, nDays) |
qtDT_F_DateSubDaysReturns a date that is the result of substracting days from a given date More... | |
integer(qtdt_k_int1) function | qtdt_f_dayofweek (tDate) |
qtDT_F_DayOfWeekReturns the day of week (1 - 7) for a given date More... | |
integer(qtdt_k_int1) function | qtdt_f_weekofyear (tDate) |
qtDT_F_WeekOfYearReturns the week number for a given date More... | |
type(qtdt_t_time) function | qtdt_f_timenow (lUTC) |
qtDT_F_TimeNowReturns the current time. More... | |
real(qtdt_k_real8) function | qtdt_f_timetorealms (tTime) |
qtDT_F_TimeToRealMSConverts a time value into a real value. More... | |
integer(qtdt_k_int4) function | qtdt_f_timetointegerms (tTime) |
qtDT_F_TimeToIntegerMSConverts a time value into an integer value. More... | |
type(qtdt_t_time) function | qtdt_f_millisecondstotime8 (timeMS) |
qtDT_F_MillisecondsToTimeConverts a time specification in milliseconds into a time type. More... | |
type(qtdt_t_time) function | qtdt_f_millisecondstotime4 (timeMS) |
type(qtdt_t_time) function | qtdt_f_millisecondstotimei (iTimeMS) |
type(qtdt_t_daytime) function | qtdt_f_millisecondstodaytime8 (timeMS) |
qtDT_F_MillisecondsToDayTimeConverts a time specification in milliseconds into a daytime type. More... | |
type(qtdt_t_daytime) function | qtdt_f_millisecondstodaytime4 (timeMS) |
subroutine | qtdt_s_timetodaytime (tDayTime, tTime) |
qtDT_S_TimeToDayTimeConverts a time type into a daytime type. More... | |
subroutine | qtdt_s_daytimetotime (tTime, tDayTime) |
qtDT_S_DayTimeToTimeConverts a daytime type into a time type. More... | |
logical function | qtdt_f_isvalidtime (tTime) |
qtDT_F_IsValidTimeChecks if the time value is valid More... | |
logical function | qtdt_f_isvaliddaytime (tDayTime) |
qtDT_F_IsValidDayTimeChecks if the daytime value is valid More... | |
logical function | qtdt_f_timeeq (tTime1, tTime2) |
qtDT_F_TimeEQCompares if two time values are equal. More... | |
logical function | qtdt_f_timene (tTime1, tTime2) |
qtDT_F_TimeNECompares if two time values are not equal. More... | |
logical function | qtdt_f_timege (tTime1, tTime2) |
qtDT_F_TimeGEChecks for a time value being greater than another or equal to it. More... | |
logical function | qtdt_f_timegt (tTime1, tTime2) |
qtDT_F_TimeGTChecks if a time value is greater than another. More... | |
logical function | qtdt_f_timelt (tTime1, tTime2) |
qtDT_F_TimeLTChecks if a time value is lower than another. More... | |
logical function | qtdt_f_timele (tTime1, tTime2) |
qtDT_F_TimeLEChecks if a time value is lower than another or equal to it. More... | |
type(qtdt_t_time) function | qtdt_f_timedifference (tTime2, tTime1) |
qtDT_F_TimeDifferenceReturns the difference of two time values More... | |
type(qtdt_t_time) function | qtdt_f_timeplustime (tTime1, tTime2) |
qtDT_F_TimePlusTimeReturns a time that is the result of adding two time values More... | |
type(qtdt_t_timestamp) function, target | qtdt_f_currenttimestamp () |
qtDT_F_CurrentTimeStampGet current date & time More... | |
integer function | qtdt_f_stopwatch (iOpKey, iTimerID) |
qtDT_F_StopWatchStopwatch functions (in milliseconds). More... | |
Public Attributes | |
type(qtdt_t_date), parameter | qtdt_t_tdatezero = qtDT_T_Date(0, 0, 0) |
qtDT_T_Date initialization value More... | |
type(qtdt_t_time), parameter | qtdt_t_timezero = qtDT_T_Time(0, 0, 0, 0) |
qtDT_T_Time initialization value More... | |
type(qtdt_t_timestamp), parameter | qtdt_t_timestampzero = qtDT_T_TimeStamp(qtDT_T_tDateZero, qtDT_T_TimeZero) |
qtDT_T_TimeStamp initialization value More... | |
integer, dimension(12), parameter | qtdt_i_monthdays = (/31,28,31,30,31,30, 31,31,30,31,30,31/) |
days in a month (non leap-year) More... | |
integer, dimension(12), parameter | qtdt_i_monthcumdays = (/0,31,59,90,120,151,181, 212,243,273,304,334/) |
cumulated days for non leap-years More... | |
integer, parameter | qtdt_i_yeardays = 365 |
type(qtdt_t_time), parameter | qtdt_t_timecnvmaxms = qtDT_T_Time(596, 31, 23, 647) |
Limit for time conversions into to milliseconds (< 2^31 = 2147483648) time (hhh:mm:ss:ms) 596:31:23:647 = 2147483647 [ms]. More... | |
type(qtdt_t_daytime), parameter | qtdt_t_daytimecnvmaxms = qtDT_T_DayTime(24, 20, 31, 23, 647) |
Conversion of time (hhh:mm:ss:ms) to daytimee (days hh:mm:ss:ms) 2147483647 [ms] = 596:31:23:647 = 24 days 20:31:23:647. More... | |
integer, parameter | qtdt_i_secondsperday = 24 * 60 * 60 |
Seconds per day (24h * 60 min/h * 60 sec/min) More... | |
integer, parameter | qtdt_i_millisecondsperday = qtDT_I_SecondsPerDay * 1000 |
integer, parameter | qtdt_i_reset = 0 |
Stopwatch key: Reset. More... | |
integer, parameter | qtdt_i_start = 1 |
Stopwatch key: Start. More... | |
integer, parameter | qtdt_i_stop = 2 |
Stopwatch key: Stop. More... | |
integer, parameter | qtdt_i_pause = 3 |
Stopwatch key: Pause. More... | |
integer, parameter | qtdt_i_resume = 4 |
Stopwatch key: Resume. More... | |
Overview
The MODULE qtDateTime supplies TYPEs, FUNCTIONs, and SUBROUTINEs for date and time calculations.
The date calculations are based on the Gregorian calendar (enacted in 1582).
Two essential TYPEs are supplied:
TYPE qtDT_T_Date
TYPE qtDT_T_Time
The MODULE overloads some elemental Fortran operators such as
+ - = < <= == /= > >=
to allow for arithmetic operations, relational expressions, and assignments with qtDT_T_Date type variables:
TYPE(qtDT_T_Date) tDate1, tDate2 INTEGER nDays, iaDate(3) LOGICAL lRet ! assignments tDate1 = (/31,12,2012/) ! 'qtDT_T_Date = INTEGER array(3)' iaDate(:) = tDate1 ! 'INTEGER array(3) = qtDT_T_Date' ! arithmetic operations tDate2 = tDate1 + nDays ! 'qtDT_T_Date = qtDT_T_Date + INTEGER' tDate1 = tDate2 - nDays ! 'qtDT_T_Date = qtDT_T_Date - INTEGER' tDate2 = nDays + tDate1 ! 'qtDT_T_Date = INTEGER + qtDT_T_Date' nDays = tDate2 - tDate1 ! 'INTEGER = qtDT_T_Date - qtDT_T_Date' ! relational expressions of the form 'qtDT_T_Date .relational operator. qtDT_T_Date' lRet = ( tDate1 < tDate2 ) lRet = ( tDate1 <= tDate2 ) lRet = ( tDate1 == tDate2 ) lRet = ( tDate1 /= tDate2 ) lRet = ( tDate1 > tDate2 ) lRet = ( tDate1 >= tDate2 )
And with qtDT_T_Time type variables you may operate similarily:
TYPE(qtDT_T_Time) tTime1, tTime2, tTime3 LOGICAL lRet ! there is no assignment like qtDT_T_Time = INTEGER array(4) provided ! but you can use the TYPE constructor function (as with any other TYPE) tTime1 = qtDT_T_Time(31,12,2012/) ! note the sequence: day, month, year ! arithmetic operations tTime3 = tTime1 + tTime2 ! qtDT_T_Time = qtDT_T_Time + qtDT_T_Time tTime3 = tTime2 - tTime1 ! qtDT_T_Time = qtDT_T_Time - qtDT_T_Time ! relational expressions of the form ! 'qtDT_T_Time .relational operator. qtDT_T_Time' lRet = ( tTime2 < tTime1 ) lRet = ( tTime2 <= tTime1 ) lRet = ( tTime2 == tTime1 ) lRet = ( tTime2 /= tTime1 ) lRet = ( tTime2 > tTime1 ) lRet = ( tTime2 >= tTime1 )
The TYPE qtDT_T_Time is designed to allow for hour specifications greater than 23 hours. If you want to restrict a time specification to the time of day (i.e.v.: a clock time <= 23:59:59:999) then you may use the TYPE qtDT_T_DayTime which allows to specify a number of days ("24 hour blocks"). The assignment operator (=) is overloaded to convert between the qtDT_T_Time and qtDT_T_DayTime type.
TYPE(qtDT_T_Time) tTime TYPE(qtDT_T_DayTime) tDayTime ! Initialization of variable tDayTime using the TYPE constructor function. ! The argument sequence is: days, hours, minutes, seconds, milliseconds tDayTime = qtDT_T_DayTime(24,20,31,23,647) ! = 2**31 - 1 [ms] = 2147483647 [ms] tTime = tDayTime ! gives tTime = qtDT_T_Time(596,31,23,647) tDayTime = tTime ! assignment works both ways ! Annotation: tDayTime is initialized with a value which correlates to the ! maximum value of a 4-byte INTEGER variable (2147483647). This is because ! the value in tTime should not be greater than this (596:31:23:647 correlates ! to 2147483647 [ms]; see [qtDT_F_TimeToIntegerMS](qtDT_F_TimeToIntegerMS) for an explanation).
The operator and assignment overloadings are created by usage of several procedures that you find in the module. Moreover there are other functions that are hopefully useful for you:
TYPE(qtDT_T_Date) tDate TYPE(qtDT_T_Time) tTime INTEGER iDate, iRet, nDays, iMonth, iYear, iDoY, iDoW, iWoY REAL rTimeMS INTEGER iTimeMS TYPE(qtDT_T_TimeStamp) tDateTime ! -------------- ! date functions tDate = qtDT_F_DateToday( ) ! returns today's date iDate = qtDT_F_DateToInteger( tDate ) ! converts a date into an integer value iRet = qtDT_F_LeapYear( iYear ) ! Checks, if iYear is a leap-year (it is: iRet = 0, it is not: iRet = 1) iRet = qtDT_F_DaysInYear( iYear ) ! returns either 365 or 366 (if leap-year) nDays = qtDT_F_DaysInMonth( iMonth, iYear ) ! returns the number of days of a month for the specified year nDays = qtDT_F_CumulatedDays( iMonth, iYear ) ! returns the cumulated number of days in the months of a year before the given month iDoY = qtDT_F_DayOfYear( tDate ) ! returns the day of year (1 till 365 or 366) for a given date tDate = qtDT_F_DayOfYearToDate( iDoY, iYear ) ! determines the date for a given day of year (1 till 365 or 366) iDoW = qtDT_F_DayOfWeek( tDate ) ! returns the day of week (1 - 7) for a given date iWoY = qtDT_F_WeekOfYear( tDate ) ! returns the week number (1 - 53) for a given date ! -------------- ! time functions tTime = qtDT_F_TimeNow( ) ! returns the current time rTimeMS = qtDT_F_TimeToRealMS( tTime ) ! converts a time value into a real value [ms] iTimeMS = qtDT_F_TimeToIntegerMS( tTime ) ! converts a time value into an integer value [ms] tTime = qtDT_F_MillisecondsToTime( timeMS ) ! converts a time specification in milliseconds into a time type value tDayTime = qtDT_F_MillisecondsToDayTime( timeMS ) ! converts a time specification in milliseconds into a daytime type value tDateTime = qtDT_F_CurrentTimeStamp( ) ! get current date & time iTimeMS = qtDT_F_StopWatch( iOpKey [, iTimerId] ) ! stopwatch functions (start, stop, pause, resume)
You will note, some of the functions are available in variants allowing different argument types to be specified. For example, the function qtDT_F_DaysInMonth can also be called with a qtDT_T_Date type argument:
nDays = qtDT_F_DaysInMonth( tDate )
A note regarding the documentation (the on-line help)
For documentation of the qtDateTime module, the documentation tool "doxygen" has been used. It lists symbols (names of functions, subroutines, parameters) in the MODULE as members of a "class". Therefore, you will find TYPEs, FUNCTIONs, and SUBROUTINEs etc. being part of the "Data Types List" of qtdatetime.
Usage & Initialization
Specifiy the qtDateTime MODULE in the program unit where you want to use qtDateTime procedures, structures (TYPEs), and constants (PARAMETERs).
USE qtDateTime
This also means, you need to specify the MODULE path of the file qtDateTime.mod such that the compiler can find it.
And also, for correct linking, the qtDateTime library (.lib) appropriate to your compiler has to be referenced (for example: for Intel Visual Fortran link qtDateTimeIVF32.lib when creating a 32-bit application).
Before using any procedure of qtDateTime initialize it. Either
CALL qtDT_S_Initialization('evaluation')
or, if you own a qtDateTime licence, replace the statement before by one which specifies your licence number. E.g.:
CALL qtDT_S_Initialization('L7496-402157')
If you don't initialize qtDateTime, your program will terminate as soon as your program uses a qtDateTime function.
First Release 1.00: 15. August 2014
Documentation: 15. August 2014
Version 1.01: 11. September 2014
Documentation: 11. September 2014
tTime = qtDT_F_TimeNow( lUTC=.TRUE. ) ! returns time according to GMT/UTC
Version 1.02: 12. December 2015
Documentation: 07. January 2016
tDateE = tDateS - nDays
tDateE = qtDT_F_DateSubDays( tDateS, nDays )
subroutine qtdt_s_initialization | ( | character(*), intent(in) | cLicenceNumber | ) |
Usage:
CALL qtDT_S_Initialization( cLicenceNumber )
cLicenceNumber | : either licence number (format: L####-######) or the word 'evaluation' |
Initializes qtDateTime such that the MODULE's procedures can be used.
For unrestricted use, a valid licence number has to specified (will be obtained when a qtDateTime licence has been purchased). The licence number has the format L####-###### (e.g.: L1234-123456).
If the word 'evaluation' has been specified on entry of qtDT_S_Initialization, a message appears which notifies the user of the time limited use.
type (qtdt_t_date) function qtdt_f_datetoday | ( | ) |
Usage:
tDate = qtDT_F_DateToday( )
Returns the date of today. Internally, the intrinsic procedure DATE_AND_TIME is called to determine the current date.
integer (qtdt_k_int4) function qtdt_f_datetointeger | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
iDate = qtDT_F_DateToInteger( tDate )
tDate | : date to convert |
Converts a date specification (dd.mm.yyyy) into an 4-byte integer number (yyyymmdd).
subroutine qtdt_s_int4arraytodate | ( | type (qtdt_t_date), intent(out) | tDate, |
integer (qtdt_k_int4), dimension(3), intent(in) | iaDate | ||
) |
Usage:
CALL qtDT_F_IntegerArrayToDate( tDate, iaDate ) ! tDate = iaDate(:)
tDate | : the date type (result of conversion) |
iaDate | : integer array containing a date specification (/day,month,year/) to convert |
Converts a date specification in an array (/day, month, year/) into a date type.
This procedure is used to overload the assignment operator (=) to allow for assignments like
TYPE (qtDT_T_Date) :: tDate INTEGER :: day = 3, month = 8, year = 1998 INTEGER :: iaDate = (/1,4,2012/) tDate = (/day, month, year/) tDate = iaDate
subroutine qtdt_s_int2arraytodate | ( | type (qtdt_t_date), intent(out) | tDate, |
integer (qtdt_k_int2), dimension(3), intent(in) | iaDate | ||
) |
subroutine qtdt_s_datetoint4array | ( | integer (qtdt_k_int4), dimension(3), intent(out) | iaDate, |
type (qtdt_t_date), intent(in) | tDate | ||
) |
Usage:
CALL qtDT_S_DateToIntegerArray( iaDate, tDate ) ! iaDate(:) = tDate
iaDate | : integer array; result of conversion: (/day,month,year/) |
tDate | : the date type value containing a date specification to be converted |
Converts a date type value into an array (/day, month, year/).
This procedure is used to overload the assignment operator (=) to allow for assignments like
TYPE (qtDT_T_Date) :: tDate = INTEGER :: iaDate tDate = qtDT_T_Date(28,4,2014) iaDate(:) = tDate
subroutine qtdt_s_datetoint2array | ( | integer (qtdt_k_int2), dimension(3), intent(out) | iaDate, |
type (qtdt_t_date), intent(in) | tDate | ||
) |
logical function qtdt_f_isvaliddate | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
lValid = qtDT_F_IsValidDate( tDate )
tDate | : date to be checked |
The date given is checked for validity (year >= 0, 1 <= month <= 12, 1 <= day <= days in month).
If the date is valid, .TRUE. is returned.
If the date is not valid, .FALSE. is returned.
logical function qtdt_f_dateeq | ( | type (qtdt_t_date), intent(in) | tDate1, |
type (qtdt_t_date), intent(in) | tDate2 | ||
) |
Usage:
lRet = ( tDate1 == tDate2 ) lRet = qtDT_F_DateEQ( tDate1, tDate2 )
tDate1 | : date to be compared |
tDate2 | : date to be compared |
Compares if two dates are equal and returns .TRUE. if so.
The function is used to overload the logical operators .EQ. and == .
logical function qtdt_f_datene | ( | type (qtdt_t_date), intent(in) | tDate1, |
type (qtdt_t_date), intent(in) | tDate2 | ||
) |
Usage:
lRet = ( tDate1 /= tDate2 ) lRet = qtDT_F_DateNE( tDate1, tDate2 )
tDate1 | : date to be compared |
tDate2 | : date to be compared |
Compares if two dates are equal and returns .TRUE. if so.
The function is used to overload the logical operators .NE. and /= .
logical function qtdt_f_dategt | ( | type (qtdt_t_date), intent(in) | tDate1, |
type (qtdt_t_date), intent(in) | tDate2 | ||
) |
Usage:
lRet = ( tDate1 > tDate2 ) lRet = qtDT_F_DateGT( tDate1, tDate2 )
tDate1 | : date to be compared |
tDate2 | : date to be compared |
Compares if a date is greater (is more recent) than another, and returns .TRUE. if so.
For example, the date 25.4.2013 is greater than 21.8.2012.
The function is used to overload the logical operators .GT. and > .
logical function qtdt_f_datege | ( | type (qtdt_t_date), intent(in) | tDate1, |
type (qtdt_t_date), intent(in) | tDate2 | ||
) |
Usage:
lRet = ( tDate1 >= tDate2 ) lRet = qtDT_F_DateGE( tDate1, tDate2 )
tDate1 | : date to be compared |
tDate2 | : date to be compared |
Compares if a date is greater (is more recent) than another or equal to the other one, and returns .TRUE. if so.
The function is used to overload the logical operators .GE. and >= .
logical function qtdt_f_datelt | ( | type (qtdt_t_date), intent(in) | tDate1, |
type (qtdt_t_date), intent(in) | tDate2 | ||
) |
Usage:
lRet = ( tDate1 < tDate2 ) lRet = qtDT_F_DateLT( tDate1, tDate2 )
tDate1 | : date to be compared |
tDate2 | : date to be compared |
Compares if a date is lower (is older) than another, and returns .TRUE. if so.
The function is used to overload the logical operators .LT. and < .
logical function qtdt_f_datele | ( | type (qtdt_t_date), intent(in) | tDate1, |
type (qtdt_t_date), intent(in) | tDate2 | ||
) |
Usage:
lRet = ( tDate1 <= tDate2 ) lRet = qtDT_F_DateLE( tDate1, tDate2 )
tDate1 | : date to be compared |
tDate2 | : date to be compared |
Compares if a date is lower (is older) than another or equal to the other one, and returns .TRUE. if so.
The function is used to overload the logical operators .LE. and <= .
integer function qtdt_f_leapyeari | ( | integer, intent(in) | iYear | ) |
Usage:
iRet = qtDT_F_LeapYear( iYear )
iYear | : year specification |
Returns 0 if year is not a leap-year
1 if year is a leap-year
If a year is a leap-year, the month February has 29 days. Otherwise it has 28.
integer function qtdt_f_leapyeart | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
iRet = qtDT_F_LeapYear( tDate )
tDate | : date specification |
Returns 0 if year is not a leap-year
1 if year is a leap-year
If a year in a date specification is a leap-year, and if, the month February has 29 days. Otherwise it has 28.
integer function qtdt_f_daysinyeari | ( | integer(qtdt_k_int4), intent(in) | iYear | ) |
Usage:
iRet = qtDT_F_DaysInYear( iYear )
iYear | : year |
Alternative function interface see below.
integer function qtdt_f_daysinyeart | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
iRet = qtDT_F_DaysInYear( tDate )
tDate | : date specification |
Alternative function interface see above.
integer function qtdt_f_daysinmonth4 | ( | integer(qtdt_k_int4), intent(in) | iMonth, |
integer(qtdt_k_int4), intent(in) | iYear | ||
) |
Usage:
nDays = qtDT_F_DaysInMonth( iMonth, iYear )
iMonth | : month specification |
iYear | : year specification |
Returns the number of days of a month for the specified year considering if the given year is a leap-year. Thus, if iMonth = 2 (February), the function will return 29 days if a leap-year is given (e.g., iYear = 2012), otherwise 28 will be the result.
Alternative: nDays = qtDT_F_DaysInMonth( tDate )
integer function qtdt_f_daysinmonth2 | ( | integer(qtdt_k_int2), intent(in) | iMonth, |
integer(qtdt_k_int4), intent(in) | iYear | ||
) |
Usage:
nDays = qtDT_F_DaysInMonth( iMonth, iYear )
iMonth | : month specification |
iYear | : year specification |
Returns the number of days of a month for the specified year considering if the given year is a leap-year. Thus, if iMonth = 2 (February), the function will return 29 days if a leap-year is given (e.g., iYear = 2012), otherwise 28 will be the result.
Alternative: nDays = qtDT_F_DaysInMonth( tDate )
integer function qtdt_f_daysinmontht | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
nDays = qtDT_F_DaysInMonth( tDate )
tDate | : date specification (from which month and year are used) |
Returns the number of days of a month for the specified date's year and month.
Alternative: nDays = qtDT_F_DaysInMonth( iMonth, iYear )
integer function qtdt_f_cumulateddaysi4 | ( | integer(qtdt_k_int4), intent(in) | iMonth, |
integer(qtdt_k_int4), intent(in) | iYear | ||
) |
Usage:
nDays = qtDT_F_CumulatedDays( iMonth, iYear )
iMonth | : month specification |
iYear | : year specification |
The days in the months of the year are cumulated up to the month specified and returned.
So, if the month of January is given (iMonth = 1), the function will return 0.
Or for example, if iMonth = 3 (March), the function will either return 59 (= 31 + 28) or 60 (= 31 + 29), depending if a leap-year is specified (e.g., iYear = 2012) or not.
integer function qtdt_f_cumulateddaysi2 | ( | integer(qtdt_k_int2), intent(in) | iMonth, |
integer(qtdt_k_int4), intent(in) | iYear | ||
) |
integer(qtdt_k_int2) function qtdt_f_dayofyear | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
iDoY = qtDT_F_DayOfYear( tDate )
tDate | : a date specification |
Returns the day of year for a given date. Thus, the leap-year regulation is considered.
Example
USE qtDateTime TYPE (qtDT_T_Date) :: tDate INTEGER iDoY tDate = qtDT_T_Date(2,3,2014) iDoY = qtDT_F_DayOfYear( tDate ) ! should give: iDoY = 61
type (qtdt_t_date) function qtdt_f_dayofyeartodate | ( | integer(qtdt_k_int4), intent(in) | iDoY, |
integer(qtdt_k_int4), intent(in) | iYear | ||
) |
Usage:
tDate = qtDT_F_DayOfYearToDate( iDoY, iYear )
iDoY | : day of year (1 - 365|366) |
iYear | : year |
Converts a day of year specification into a date.
For example, if iDoY = 32 and iYear = 2010, then the result will be the 1st of February 2010.
If the day of year specification is greater than the number of days in the year given, then a date for a following year is calculated.
integer(qtdt_k_int4) function qtdt_f_datedifference | ( | type (qtdt_t_date), intent(in) | tDate2, |
type (qtdt_t_date), intent(in) | tDate1 | ||
) |
Usage:
nDays = tDate2 - tDate1 nDays = qtDT_F_DateDifference( tDate2, tDate1 )
tDate2 | : date to subtract tDate1 from |
tDate1 | : date to be substracted |
Substracts one date from another and returns the difference as the number of days. If the date given in the first argument is older than the second one, then a negative value is returned.
If an invalid date is specified, the function returns the value of -HUGE(nDays) .
The function is used to overload the operator - .
type (qtdt_t_date) function qtdt_f_dateadddays | ( | type (qtdt_t_date), intent(in) | tDateS, |
integer(qtdt_k_int4), intent(in) | nDays | ||
) |
Usage:
tDateE = tDateS + nDays tDateE = nDays + tDate1 tDateE = qtDT_F_DateAddDays( tDateS, nDays ) tDateE = qtDT_F_DateAddDays( nDays, tDateS )
tDateS | : date |
nDays | : number of days added to tDateS (or substracted from tDateS when negative) |
Returns the date that is the result of a given date to which is added a number of days. If the number of days given is negative than these days are substracted from the given date.
If an invalid date is specified, the function returns the value of qtDT_T_Date(-1,-1,-1) .
The function is used to overload the operators + and - .
type (qtdt_t_date) function qtdt_f_dateadddays2 | ( | integer(qtdt_k_int4), intent(in) | nDays, |
type (qtdt_t_date), intent(in) | tDateS | ||
) |
type (qtdt_t_date) function qtdt_f_datesubdays | ( | type (qtdt_t_date), intent(in) | tDateS, |
integer(qtdt_k_int4), intent(in) | nDays | ||
) |
Usage:
tDateE = tDateS - nDays tDateE = qtDT_F_DateSubDays( tDateS, nDays )
tDateS | : date |
nDays | : number of days substracted from tDateS |
Returns the date that is the result of a given date to which is added a number of days. If the number of days given is negative than these days are substracted from the given date.
If an invalid date is specified, the function returns the value of qtDT_T_Date(-1,-1,-1) .
The function is used to overload the operators + and - .
integer(qtdt_k_int1) function qtdt_f_dayofweek | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
iDoW = qtDT_F_DayOfWeek( tDate )
tDate | : date for which the day of the week is to be determined |
For a given date the day of week (weekday) is determined.
1: Monday 2: Tuesday 3: Wednesday 4: Thursday 5: Friday 6: Saturday 7: Sunday -1: invalid date (date does not exist)
integer(qtdt_k_int1) function qtdt_f_weekofyear | ( | type (qtdt_t_date), intent(in) | tDate | ) |
Usage:
iWoY = qtDT_F_WeekOfYear( tDate )
tDate | : date for which the week number is to be determined |
For a given date the week number is determined. If the date given is valid, qtDT_F_WeekOfYear returns a value in the range from 1 to 53. If the date is invalid, -1 is returned.
type(qtdt_t_time) function qtdt_f_timenow | ( | logical, intent(in), optional | lUTC | ) |
Usage:
tTime = qtDT_F_TimeNow( ) tTime = qtDT_F_TimeNow( lUTC=.TRUE .)
This function calls the intrinsic procedure DATE_AND_TIME to obtain the current time (hh:mm:ss:ms). If the optional argument is set .TRUE. the time with respect to UTC is returned (UTC = Universal Time, Coordinated). Otherwise the local time is returned (default: lUTC=.FALSE.).
Note, that the time returned also reflects daylight saving time settings of the current system (for local time as well as for UTC).
real (qtdt_k_real8) function qtdt_f_timetorealms | ( | type (qtdt_t_time), intent(in) | tTime | ) |
Usage:
rTimeMS = qtDT_F_TimeToRealMS( tTime )
tTime | : time to be converted into milliseconds (a 8-byte real) |
Converts a time value (hh:mm:ss:ms) into a 8-byte real number specifying that time im milliseconds.
integer(qtdt_k_int4) function qtdt_f_timetointegerms | ( | type(qtdt_t_time), intent(in) | tTime | ) |
Usage:
iTimeMS = qtDT_F_TimeToIntegerMS( tTime )
tTime | : time to be converted into milliseconds (a 4-byte integer) |
Converts a time value (hh:mm:ss:ms) into a 4-byte integer number specifying that time im milliseconds. Please note, that the maximum value of a 4-byte INTEGER is 2**31 - 1 = 2147483647. Thus, the argument tTime must not be greater than 596:31:23:647.
type (qtdt_t_time) function qtdt_f_millisecondstotime8 | ( | real (qtdt_k_real8), intent(in) | timeMS | ) |
Usage:
tTime = qtDT_F_MillisecondsToTime( timeMS )
timeMS | : time in milliseconds |
Converts a time specification in milliseconds into a time type.
Please note that the time im milliseconds must be less than 2**31 (=2147483648; allowing for a resulting time of at most 596:31:23:647).
type (qtdt_t_time) function qtdt_f_millisecondstotime4 | ( | real (qtdt_k_real4), intent(in) | timeMS | ) |
type (qtdt_t_time) function qtdt_f_millisecondstotimei | ( | integer (qtdt_k_int4), intent(in) | iTimeMS | ) |
type (qtdt_t_daytime) function qtdt_f_millisecondstodaytime8 | ( | real (qtdt_k_real8), intent(in) | timeMS | ) |
Usage:
tDayTime = qtDT_F_MillisecondsToDayTime( timeMS )
timeMS | : time in milliseconds |
Converts a time specification in milliseconds into a daytime type.
type (qtdt_t_daytime) function qtdt_f_millisecondstodaytime4 | ( | real (qtdt_k_real4), intent(in) | timeMS | ) |
subroutine qtdt_s_timetodaytime | ( | type (qtdt_t_daytime), intent(out) | tDayTime, |
type (qtdt_t_time), intent(in) | tTime | ||
) |
Usage:
CALL qtDT_S_TimeToDayTime( tDayTime, tTime )
tDayTime | : daytime type value |
tTime | : time type value |
Converts a time type value into a daytime type value.
This procedure is used to overload the assignment operator (=) allowing for statements like
TYPE (qtDT_T_DayTime) :: tDayTime TYPE (qtDT_T_Time) :: tTime = qtDT_T_Time(123, 40, 10, 312) tDayTime = tTime ! giving: tDayTime = qtDT_T_DayTime(5, 3, 40, 10, 312)
subroutine qtdt_s_daytimetotime | ( | type (qtdt_t_time), intent(out) | tTime, |
type (qtdt_t_daytime), intent(in) | tDayTime | ||
) |
Usage:
CALL qtDT_S_DayTimeToTime( tTime, tDayTime )
tTime | : time type value |
tDayTime | : daytime type value |
Converts a daytime type value into a time type value.
Since the time type value is restricted to a maximum value of 596:31:23:647 (see qtDT_F_TimeToIntegerMS for explanation), tDayTime days should not exceed the value of 24 days, otherwise the function will return faulty values.
This procedure is used to overload the assignment operator (=) allowing for statements like
TYPE (qtDT_T_DayTime) :: tDayTime = qtDT_T_DayTime(5, 3, 40, 10, 312) TYPE (qtDT_T_Time) :: tTime tTime = tDayTime ! giving: tTime = qtDT_T_Time(123, 40, 10, 312)
logical function qtdt_f_isvalidtime | ( | type (qtdt_t_time), intent(in) | tTime | ) |
Usage:
lValid = qtDT_F_IsValidTime( tTime )
tTime | : time to be checked |
The time given is checked for validity (hours >= 0, 0 <= minutes <= 59, 0 <= seconds <= 59, 0 <= milliseconds <= 999).
If the time is valid, .TRUE. is returned.
If the time is not valid, .FALSE. is returned.
logical function qtdt_f_isvaliddaytime | ( | type (qtdt_t_daytime), intent(in) | tDayTime | ) |
Usage:
lValid = qtDT_F_IsValidDayTime( tDayTime )
tDayTime | : daytime to be checked |
The daytime given is checked for validity (days >= 0, 0 <= hours <= 23, 0 <= minutes <= 59, 0 <= seconds <= 59, 0 <= milliseconds <= 999).
If the time is valid, .TRUE. is returned.
If the time is not valid, .FALSE. is returned.
logical function qtdt_f_timeeq | ( | type (qtdt_t_time), intent(in) | tTime1, |
type (qtdt_t_time), intent(in) | tTime2 | ||
) |
Usage:
lRet = ( tTime1 == tTime2 ) lRet = qtDT_F_TimeEQ( tTime1, tTime2 )
tTime1 | : time to be compared |
tTime2 | : time to be compared |
Compares if two time values are equal and returns .TRUE. if so.
The function is used to overload the logical operators .EQ. and == .
logical function qtdt_f_timene | ( | type (qtdt_t_time), intent(in) | tTime1, |
type (qtdt_t_time), intent(in) | tTime2 | ||
) |
Usage:
lRet = ( tTime1 /= tTime2 ) lRet = qtDT_F_TimeNE( tTime1, tTime2 )
tTime1 | : time to be compared |
tTime2 | : time to be compared |
Compares if two time values are not equal and returns .TRUE. if so.
The function is used to overload the logical operators .NE. and /= .
logical function qtdt_f_timege | ( | type (qtdt_t_time), intent(in) | tTime1, |
type (qtdt_t_time), intent(in) | tTime2 | ||
) |
Usage:
lRet = ( tTime1 >= tTime2 ) lRet = qtDT_F_TimeGE( tTime1, tTime2 )
tTime1 | : time to be compared |
tTime2 | : time to be compared |
Compares if a time value is greater (later) than another or equal to the other one, and returns .TRUE. if so.
The function is used to overload the logical operators .GE. and >= .
logical function qtdt_f_timegt | ( | type (qtdt_t_time), intent(in) | tTime1, |
type (qtdt_t_time), intent(in) | tTime2 | ||
) |
Usage:
lRet = ( tTime1 > tTime2 ) lRet = qtDT_F_TimeGT( tTime1, tTime2 )
tTime1 | : time to be compared |
tTime2 | : time to be compared |
Compares if a time value is greater (later) than another, and returns .TRUE. if so.
For example, the time 23:41:06:566 is greater than 22:59:01:398.
The function is used to overload the logical operators .GT. and > .
logical function qtdt_f_timelt | ( | type (qtdt_t_time), intent(in) | tTime1, |
type (qtdt_t_time), intent(in) | tTime2 | ||
) |
Usage:
lRet = ( tTime1 < tTime2 ) lRet = qtDT_F_TimeLT( tTime1, tTime2 )
tTime1 | : time to be compared |
tTime2 | : time to be compared |
Compares if a time value is lower (earlier) than another, and returns .TRUE. if so.
The function is used to overload the logical operators .LT. and < .
logical function qtdt_f_timele | ( | type (qtdt_t_time), intent(in) | tTime1, |
type (qtdt_t_time), intent(in) | tTime2 | ||
) |
Usage:
lRet = ( tTime1 <= tTime2 ) lRet = qtDT_F_TimeLE( tTime1, tTime2 )
tTime1 | : time to be compared |
tTime2 | : time to be compared |
Compares if a time value is lower (earlier) than another or equal to it, and returns .TRUE. if so.
The function is used to overload the logical operators .LE. and <= .
type (qtdt_t_time) function qtdt_f_timedifference | ( | type (qtdt_t_time), intent(in) | tTime2, |
type (qtdt_t_time), intent(in) | tTime1 | ||
) |
Usage:
tTimeDiff = tTime2 - tTime1 tTimeDiff = qtDT_F_TimeDifference( tTime2, tTime1 )
tTime2 | : time to subtract tTime1 from |
tTime1 | : time to be substracted |
Substracts one time from another and returns the absolute value of the difference. Thus, even if the time given in the first argument is less than the second one, positive values are returned in all components of the type.
The function is used to overload the operator - .
type (qtdt_t_time) function qtdt_f_timeplustime | ( | type (qtdt_t_time), intent(in) | tTime1, |
type (qtdt_t_time), intent(in) | tTime2 | ||
) |
Usage:
tTime3 = tTime1 + tTime2 tTime3 = qtDT_F_TimePlusTime( tTime1, tTime2 )
tTime1 | : time1 |
tTime2 | : time2 to be added to time1 |
Returns a time that is the result of adding two time values.
The function is used to overload the operator + .
type(qtdt_t_timestamp) function, target qtdt_f_currenttimestamp | ( | ) |
Usage:
tDateTime = qtDT_F_CurrentTimeStamp( )
Returns the date of today and the current time.
Internally, the intrinsic procedure DATE_AND_TIME is called.
integer function qtdt_f_stopwatch | ( | integer, intent(in) | iOpKey, |
integer, intent(in), optional | iTimerID | ||
) |
Usage:
iTimeTodayMS = qtDT_F_StopWatch( qtDT_I_Start ) ! start default timer iTimeElapsedMS = qtDT_F_StopWatch( qtDT_I_Stop ) ! get time elapsed since start of default timer iTimeElapsedMS = qtDT_F_StopWatch( qtDT_I_Pause ) ! pause default stopwatch timer iTimePausedMS = qtDT_F_StopWatch( qtDT_I_Resume ) ! resume default stopwatch timer after pause iTimeTodayMS = qtDT_F_StopWatch( qtDT_I_Start, iTimerId ) ! start specified stopwatch timer iTimeElapsedMS = qtDT_F_StopWatch( qtDT_I_Stop, iTimerId ) ! get time elapsed since start of specified timer iTimeElapsedMS = qtDT_F_StopWatch( qtDT_I_Pause, iTimerId ) ! pause specified stopwatch timer iTimePausedMS = qtDT_F_StopWatch( qtDT_I_Resume, iTimerId ) ! resume specified stopwatch timer after pause
iOpKey | = qtDT_I_Start: Start; function returns time of day in ms = qtDT_I_Stop: Stop; the time elapsed since "Start" less pausing time is returned [in ms] = qtDT_I_Pause: Pause timer; function returns time elapsed since "Start" less previous cumulated pausing time [in ms] = qtDT_I_Resume: Resume timer after "Pause"; function returns pausing time (the interim time since begin of last pause) [in ms] = qtDT_I_Reset: Reset (release timer ID); function returns 0. |
iTimerID | : [optional] argument for identification of a specified timer (numbered from 1 to to 50; can be used concurrently) |
The function allows to measure times like a stopwatch. /n To start it call qtDT_F_StopWatch with argument key qtDT_I_Start. /n To get the time elapsed since start (less cumulated pausing time) use key qtDT_I_Stop. You may call the function with this key several times consecutively. /n To pause the stopwatch, use key qtDT_I_Pause. The function will return the time elapsed since start (less cumulated pausing time) /n To resume the stopwatch after a pause, use key qtDT_I_Resume. The function will return the pausing time (time elapsed since key qtDT_I_Pause was used). /n To reset a stopwatch, which means to release a timer ID and to have all internal values of the timer set to 0, call the function with argument key qtDT_I_Reset. A reset of a timer is usually not necessary, but the function is supplied to be able to generate an initial state for a timer. You may also call it with qtDT_I_Start, to start the stopwatch again.
If no specific timer id is given, a default timer is being used.
You may measure the time of up to 50 different activities of your program concurrently by specifying a timer ID (numbered 1 to 50).
type(qtdt_t_date), parameter qtdt_t_tdatezero = qtDT_T_Date(0, 0, 0) |
qtDT_T_Date initialization value
type (qtdt_t_time), parameter qtdt_t_timezero = qtDT_T_Time(0, 0, 0, 0) |
qtDT_T_Time initialization value
type(qtdt_t_timestamp), parameter qtdt_t_timestampzero = qtDT_T_TimeStamp(qtDT_T_tDateZero, qtDT_T_TimeZero) |
qtDT_T_TimeStamp initialization value
integer, dimension(12), parameter qtdt_i_monthdays = (/31,28,31,30,31,30, 31,31,30,31,30,31/) |
days in a month (non leap-year)
integer, dimension(12), parameter qtdt_i_monthcumdays = (/0,31,59,90,120,151,181, 212,243,273,304,334/) |
cumulated days for non leap-years
integer, parameter qtdt_i_yeardays = 365 |
type (qtdt_t_time), parameter qtdt_t_timecnvmaxms = qtDT_T_Time(596, 31, 23, 647) |
Limit for time conversions into to milliseconds (< 2^31 = 2147483648)
time (hhh:mm:ss:ms) 596:31:23:647 = 2147483647 [ms].
type (qtdt_t_daytime), parameter qtdt_t_daytimecnvmaxms = qtDT_T_DayTime(24, 20, 31, 23, 647) |
Conversion of time (hhh:mm:ss:ms) to daytimee (days hh:mm:ss:ms)
2147483647 [ms] = 596:31:23:647 = 24 days 20:31:23:647.
integer, parameter qtdt_i_secondsperday = 24 * 60 * 60 |
Seconds per day (24h * 60 min/h * 60 sec/min)
integer, parameter qtdt_i_millisecondsperday = qtDT_I_SecondsPerDay * 1000 |
integer, parameter qtdt_i_reset = 0 |
Stopwatch key: Reset.
integer, parameter qtdt_i_start = 1 |
Stopwatch key: Start.
integer, parameter qtdt_i_stop = 2 |
Stopwatch key: Stop.
integer, parameter qtdt_i_pause = 3 |
Stopwatch key: Pause.
integer, parameter qtdt_i_resume = 4 |
Stopwatch key: Resume.