libSUFR
a LIBrary of Some Useful Fortran Routines
All Classes Namespaces Files Functions Variables Pages
sufr_date_and_time Module Reference

Procedures for manipulation of date and time. More...

Functions/Subroutines

elemental real(double) function cal2jd (yy, mm, dd)
 Convert a calendar date to JD. Input and output in UT.
 
elemental subroutine jd2cal (jd, yy, mm, dd)
 Convert a Julian day to a calendar date (fractional day) - in UT.
 
elemental real(double) function year2jd (year)
 Convert a year (with decimals) to a JD. Input and output in UT.
 
elemental subroutine jd2ymdhms (jd, yy, mm, d, h, m, s)
 Convert a Julian day to date and time (h,m,s, UT)
 
elemental character function, dimension(15) jd2datestr (jd)
 Convert a Julian day to a date string (yyyy-mm-dd)
 
elemental real(double) function jd2time (jd)
 Convert a Julian day to time (UT, h)
 
elemental real(double) function jd2year (jd)
 Convert a Julian day to decimal year (e.g. 2000.0)
 
elemental subroutine jd2datetime (jd, year, month, day, time)
 Convert a Julian day to a date (y,m,d) and time (UT, h)
 
elemental real(double) function ymdhms2jd (yy, mmo, dd, h, m, s)
 Convert date and time (y,m,d, h,m,s) to JD. Input and output in UT.
 
elemental subroutine consistent_date_time (year, month, day, hour, minute, second)
 Ensure date and time are consistent after manipulation (0<month<13, 0<=minute<60, etc.)
 
elemental real(double) function dtm2jd (yy, mo, dd, time)
 Convert date and time (h) to a Julian day - input in UT.
 
elemental subroutine tm2hm (tm, h, m)
 Convert time (h) to hours and (integer) minutes.
 
elemental subroutine tm2hmm (tm, h, m)
 Convert time (h) to hours and (decimal) minutes.
 
elemental subroutine tm2hms (tm, h, m, s)
 Convert time (h) to hours, minutes and (integer) seconds.
 
elemental subroutine tm2hmss (tm, h, m, s)
 Convert time (h) to hours, minutes and (decimal) seconds.
 
elemental integer function dow_ut (jd0)
 Calculates day of week (0 = Sunday, ..., 6 = Saturday). Output for timezone of input - call dow_ut(jd+tz/24.d0) for local time.
 
elemental integer function dow_iso (jd0)
 Calculates ISO day of week (1 = Monday, ..., 7 = Sunday). Output for timezone of input - call dow_ut(jd+tz/24.d0) for local time.
 
elemental integer function doy (jd0)
 Calculate day of year (1-366) from JD.
 
elemental integer function ymd2doy (yr, mon, dy)
 Calculate day of year (1-366) from year,month,day.
 
elemental subroutine doy2md (doy, yr, mon, dy)
 Calculate month and day from day of year and year.
 
elemental integer function leapyr (yr)
 Calculate whether year is leap (1) or not (0). The number of days in February is then given by 28 + leapyr(yr) and number of days in a year by 365 + leapyr(yr)
 
elemental character function, dimension(30) jd2iso8601 (jd, tz)
 Return JD as date and time in ISO_8601 format (e.g. 2014-03-24T20:48:01+00:00)
 
elemental character function, dimension(35) jd2rfc822 (jd, tz)
 Return JD as date and time in RFC-822 format (e.g. Sat, 07 Sep 2002 23:12:01 +0100)
 
real(double) function jd2gps (jd)
 Convert a Julian day (UT) to a GPS time (seconds since 1980-01-06 - 2000-01-01 = 630720013.0)
 
real(double) function gps2jd (gpstime)
 Convert a GPS time to Julian day (UT)
 
elemental real(double) function jd2unix (jd)
 Convert a Julian day (UT) to Unix time (seconds since 1970-01-01)
 
elemental real(double) function unix2jd (unixtime)
 Convert UNIX time stamp to Julian day.
 
subroutine system_clock_2_ymdhms (year, month, day, hour, minute, second, ms, tz)
 Return system-clock date and time in (year, month, ..., minute, second and tz)
 

Detailed Description

Procedures for manipulation of date and time.

Function/Subroutine Documentation

◆ cal2jd()

elemental real(double) function sufr_date_and_time::cal2jd ( integer, intent(in) yy,
integer, intent(in) mm,
real(double), intent(in) dd )

Convert a calendar date to JD. Input and output in UT.

Parameters
yyThe year (int)
mmThe month (int)
ddThe day (double)
Return values
cal2jdThe Julian day number (double)
Note
The Gregorian calendar is assumed to start on 1582-10-15.

Definition at line 41 of file date_and_time.f90.

References cal2jd(), and sufr_kinds::double.

Referenced by cal2jd(), doy(), doy2md(), dtm2jd(), gps2jd(), jd2gps(), jd2year(), leapyr(), ymd2doy(), and ymdhms2jd().

Here is the call graph for this function:

◆ consistent_date_time()

elemental subroutine sufr_date_and_time::consistent_date_time ( integer, intent(inout) year,
integer, intent(inout) month,
integer, intent(inout) day,
integer, intent(inout) hour,
integer, intent(inout) minute,
real(double), intent(inout) second )

Ensure date and time are consistent after manipulation (0<month<13, 0<=minute<60, etc.)

Parameters
yearYear CE (I/O)
monthMonth of year (I/O)
dayDay of month (I/O)
hourHour of day (I/O)
minuteMinute (I/O)
secondSecond (I/O)

Definition at line 356 of file date_and_time.f90.

References sufr_kinds::double, jd2ymdhms(), and ymdhms2jd().

Here is the call graph for this function:

◆ dow_iso()

elemental integer function sufr_date_and_time::dow_iso ( real(double), intent(in) jd0)

Calculates ISO day of week (1 = Monday, ..., 7 = Sunday). Output for timezone of input - call dow_ut(jd+tz/24.d0) for local time.

Parameters
jd0Julian day number (double)
Return values
dow_isoThe day-of-week number, 1-7 for Mon-Sun (int)

Definition at line 543 of file date_and_time.f90.

References sufr_kinds::double, dow_iso(), and dow_ut().

Referenced by dow_iso().

Here is the call graph for this function:

◆ dow_ut()

elemental integer function sufr_date_and_time::dow_ut ( real(double), intent(in) jd0)

Calculates day of week (0 = Sunday, ..., 6 = Saturday). Output for timezone of input - call dow_ut(jd+tz/24.d0) for local time.

Parameters
jd0Julian day number (double)
Return values
dow_utThe day-of-week number, 0-6 for Sun-Sat (int)

Definition at line 520 of file date_and_time.f90.

References sufr_kinds::double, and dow_ut().

Referenced by dow_iso(), dow_ut(), jd2rfc822(), and sufr_constants::set_sufr_constants_currentdate().

Here is the call graph for this function:

◆ doy()

elemental integer function sufr_date_and_time::doy ( real(double), intent(in) jd0)

Calculate day of year (1-366) from JD.

Parameters
jd0Julian day
Return values
doyThe day of year (1-366)

Definition at line 563 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, doy(), and jd2cal().

Referenced by doy(), and doy2md().

Here is the call graph for this function:

◆ doy2md()

elemental subroutine sufr_date_and_time::doy2md ( integer, intent(in) doy,
integer, intent(in) yr,
integer, intent(out) mon,
integer, intent(out) dy )

Calculate month and day from day of year and year.

Parameters
doyDay of year number
yrYear (CE)
monMonth of year (output)
dyDay of month (output)
Note
year is input

Definition at line 615 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, doy(), and jd2cal().

Here is the call graph for this function:

◆ dtm2jd()

elemental real(double) function sufr_date_and_time::dtm2jd ( integer, intent(in) yy,
integer, intent(in) mo,
integer, intent(in) dd,
real(double), intent(in) time )

Convert date and time (h) to a Julian day - input in UT.

Parameters
yyYear (CE)
moMonth
ddDay of month
timeTime (hours)
Return values
dtm2jdJulian day

Definition at line 380 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, and dtm2jd().

Referenced by dtm2jd().

Here is the call graph for this function:

◆ gps2jd()

real(double) function sufr_date_and_time::gps2jd ( real(double), intent(in) gpstime)

Convert a GPS time to Julian day (UT)

Parameters
GPStimeGPS time: seconds since 1980-01-06
Return values
gps2jdJulian day
Todo
Check leap seconds since 2009
Note
GPS time: seconds since 1980-01-06 - 2000-01-01 = 630720013.0

Definition at line 788 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, and gps2jd().

Referenced by gps2jd().

Here is the call graph for this function:

◆ jd2cal()

elemental subroutine sufr_date_and_time::jd2cal ( real(double), intent(in) jd,
integer, intent(out) yy,
integer, intent(out) mm,
real(double), intent(out) dd )

Convert a Julian day to a calendar date (fractional day) - in UT.

Parameters
jdJulian day (UT)
yyYear (CE) (output)
mmMonth (output)
ddDay of month (+ fraction) (output)

Definition at line 89 of file date_and_time.f90.

References sufr_kinds::dbl, sufr_kinds::double, and sufr_kinds::long.

Referenced by doy(), doy2md(), jd2datestr(), jd2datetime(), jd2iso8601(), jd2rfc822(), jd2time(), jd2year(), and jd2ymdhms().

◆ jd2datestr()

elemental character function, dimension(15) sufr_date_and_time::jd2datestr ( real(double), intent(in) jd)

Convert a Julian day to a date string (yyyy-mm-dd)

Parameters
jdJulian day (UT)
Return values
jd2datestrThe date as a string (yyyy-mm-dd)

Definition at line 221 of file date_and_time.f90.

References sufr_kinds::double, jd2cal(), and jd2datestr().

Referenced by jd2datestr().

Here is the call graph for this function:

◆ jd2datetime()

elemental subroutine sufr_date_and_time::jd2datetime ( real(double), intent(in) jd,
integer, intent(out) year,
integer, intent(out) month,
integer, intent(out) day,
real(double), intent(out) time )

Convert a Julian day to a date (y,m,d) and time (UT, h)

Parameters
jdJulian day (UT). In order to obtain a local date and time, add TZ/24 to the JD.
yearYear CE (output)
monthMonth of year (output)
dayDay of the month (output)
timeTime of day (hours) (output)

Definition at line 295 of file date_and_time.f90.

References sufr_kinds::double, and jd2cal().

Here is the call graph for this function:

◆ jd2gps()

real(double) function sufr_date_and_time::jd2gps ( real(double), intent(in) jd)

Convert a Julian day (UT) to a GPS time (seconds since 1980-01-06 - 2000-01-01 = 630720013.0)

Parameters
jdJulian day (UT)
Todo
Check: leap seconds taken into account until 2022.
Return values
jd2gpsGPS time

Definition at line 738 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, and jd2gps().

Referenced by jd2gps().

Here is the call graph for this function:

◆ jd2iso8601()

elemental character function, dimension(30) sufr_date_and_time::jd2iso8601 ( real(double), intent(in) jd,
real(double), intent(in), optional tz )

Return JD as date and time in ISO_8601 format (e.g. 2014-03-24T20:48:01+00:00)

Parameters
jdJulian day (UT)
tzTime zone (optional - default: 0 = UT)
Return values
jd2iso8601Date string in ISO 8601 format.

Definition at line 660 of file date_and_time.f90.

References sufr_kinds::double, jd2cal(), jd2iso8601(), tm2hm(), and tm2hms().

Referenced by jd2iso8601().

Here is the call graph for this function:

◆ jd2rfc822()

elemental character function, dimension(35) sufr_date_and_time::jd2rfc822 ( real(double), intent(in) jd,
real(double), intent(in), optional tz )

Return JD as date and time in RFC-822 format (e.g. Sat, 07 Sep 2002 23:12:01 +0100)

Parameters
jdJulian day (UT)
tzTime zone (optional - default: 0 = UT)
Return values
jd2rfc822Date string in RFC-822 format

Definition at line 696 of file date_and_time.f90.

References sufr_kinds::double, dow_ut(), jd2cal(), jd2rfc822(), tm2hm(), and tm2hms().

Referenced by jd2rfc822().

Here is the call graph for this function:

◆ jd2time()

elemental real(double) function sufr_date_and_time::jd2time ( real(double), intent(in) jd)

Convert a Julian day to time (UT, h)

Parameters
jdJulian day (UT)
Return values
jd2timeTime in hours

Definition at line 243 of file date_and_time.f90.

References sufr_kinds::double, jd2cal(), and jd2time().

Referenced by jd2time().

Here is the call graph for this function:

◆ jd2unix()

elemental real(double) function sufr_date_and_time::jd2unix ( real(double), intent(in) jd)

Convert a Julian day (UT) to Unix time (seconds since 1970-01-01)

Parameters
jdJulian day (UT)
Return values
jd2unixUNIX time

Definition at line 833 of file date_and_time.f90.

References sufr_kinds::double, and jd2unix().

Referenced by jd2unix().

Here is the call graph for this function:

◆ jd2year()

elemental real(double) function sufr_date_and_time::jd2year ( real(double), intent(in) jd)

Convert a Julian day to decimal year (e.g. 2000.0)

Parameters
jdJulian day (UT)
Return values
jd2yearDecimal year CE

Definition at line 265 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, jd2cal(), and jd2year().

Referenced by jd2year().

Here is the call graph for this function:

◆ jd2ymdhms()

elemental subroutine sufr_date_and_time::jd2ymdhms ( real(double), intent(in) jd,
integer, intent(out) yy,
integer, intent(out) mm,
integer, intent(out) d,
integer, intent(out) h,
integer, intent(out) m,
real(double), intent(out) s )

Convert a Julian day to date and time (h,m,s, UT)

Parameters
jdJulian day (UT)
yyYear (CE, UT) (output)
mmMonth (UT) (output)
dDay (UT) (output)
hHour (UT) (output)
mMinute (UT) (output)
sSecond (+ fraction, UT) (output)

Definition at line 185 of file date_and_time.f90.

References sufr_kinds::dbl, sufr_kinds::double, and jd2cal().

Referenced by consistent_date_time().

Here is the call graph for this function:

◆ leapyr()

elemental integer function sufr_date_and_time::leapyr ( integer, intent(in) yr)

Calculate whether year is leap (1) or not (0). The number of days in February is then given by 28 + leapyr(yr) and number of days in a year by 365 + leapyr(yr)

Parameters
yrYear (CE)
Return values
leapyrLeap year (1) or no (0)

Definition at line 640 of file date_and_time.f90.

References cal2jd(), and leapyr().

Referenced by leapyr().

Here is the call graph for this function:

◆ system_clock_2_ymdhms()

subroutine sufr_date_and_time::system_clock_2_ymdhms ( integer, intent(out), optional year,
integer, intent(out), optional month,
integer, intent(out), optional day,
integer, intent(out), optional hour,
integer, intent(out), optional minute,
real(double), intent(out), optional second,
integer, intent(out), optional ms,
real(double), intent(out), optional tz )

Return system-clock date and time in (year, month, ..., minute, second and tz)

Parameters
yearYear CE (output)
monthMonth of year (output)
dayDay of month (output)
hourHour of day (output)
minuteMinute (output)
secondSecond (output)
msMillisecond (output)
tzTime zone w.r.t. Greenwich in hours - >0 = east (output)
Note
If second is present and ms is not, the milliseconds are added as a fraction to the seconds.

Definition at line 881 of file date_and_time.f90.

References sufr_kinds::double, and sufr_dummy::dumstr99.

◆ tm2hm()

elemental subroutine sufr_date_and_time::tm2hm ( real(double), intent(in) tm,
integer, intent(out) h,
integer, intent(out) m )

Convert time (h) to hours and (integer) minutes.

Parameters
tmTime (hours)
hHours (output)
mMinutes (integer) (output)

Definition at line 405 of file date_and_time.f90.

References sufr_kinds::double.

Referenced by jd2iso8601(), and jd2rfc822().

◆ tm2hmm()

elemental subroutine sufr_date_and_time::tm2hmm ( real(double), intent(in) tm,
integer, intent(out) h,
real(double), intent(out) m )

Convert time (h) to hours and (decimal) minutes.

Parameters
tmTime (hours)
hHours (output)
mMinutes (decimal) (output)

Definition at line 432 of file date_and_time.f90.

References sufr_kinds::double.

◆ tm2hms()

elemental subroutine sufr_date_and_time::tm2hms ( real(double), intent(in) tm,
integer, intent(out) h,
integer, intent(out) m,
integer, intent(out) s )

Convert time (h) to hours, minutes and (integer) seconds.

Parameters
tmTime (hours)
hHours (output)
mMinutes (output)
sSeconds (integer) (output)

Definition at line 457 of file date_and_time.f90.

References sufr_kinds::double.

Referenced by jd2iso8601(), and jd2rfc822().

◆ tm2hmss()

elemental subroutine sufr_date_and_time::tm2hmss ( real(double), intent(in) tm,
integer, intent(out) h,
integer, intent(out) m,
real(double), intent(out) s )

Convert time (h) to hours, minutes and (decimal) seconds.

Parameters
tmTime (hours)
hHours (output)
mMinutes (output)
sSeconds (output)

Definition at line 491 of file date_and_time.f90.

References sufr_kinds::double.

◆ unix2jd()

elemental real(double) function sufr_date_and_time::unix2jd ( real(double), intent(in) unixtime)

Convert UNIX time stamp to Julian day.

Parameters
unixTimeUnix time: 0 = JD 2440587.5 = 1970-01-01
Return values
unix2jdJulian day

Definition at line 853 of file date_and_time.f90.

References sufr_kinds::double, and unix2jd().

Referenced by unix2jd().

Here is the call graph for this function:

◆ year2jd()

elemental real(double) function sufr_date_and_time::year2jd ( real(double), intent(in) year)

Convert a year (with decimals) to a JD. Input and output in UT.

Parameters
yearThe year
Return values
year2jdThe Julian day number
Note
The Gregorian calendar is assumed to start on 1582-10-15.

Definition at line 149 of file date_and_time.f90.

References sufr_kinds::double, and year2jd().

Referenced by year2jd().

Here is the call graph for this function:

◆ ymd2doy()

elemental integer function sufr_date_and_time::ymd2doy ( integer, intent(in) yr,
integer, intent(in) mon,
integer, intent(in) dy )

Calculate day of year (1-366) from year,month,day.

Parameters
yrYear (CE)
monMonth
dyDay of month
Return values
ymd2doyDay of year (1-366)

Definition at line 588 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, and ymd2doy().

Referenced by ymd2doy().

Here is the call graph for this function:

◆ ymdhms2jd()

elemental real(double) function sufr_date_and_time::ymdhms2jd ( integer, intent(in) yy,
integer, intent(in) mmo,
integer, intent(in) dd,
integer, intent(in) h,
integer, intent(in) m,
real(double), intent(in) s )

Convert date and time (y,m,d, h,m,s) to JD. Input and output in UT.

Parameters
yyThe year (int)
mmoThe month (int)
ddThe day (int)
hThe hour (int)
mThe minute (int)
sThe second (double)
Return values
ymdhms2jdThe Julian day number (double)

Definition at line 325 of file date_and_time.f90.

References cal2jd(), sufr_kinds::double, and ymdhms2jd().

Referenced by consistent_date_time(), sufr_constants::set_sufr_constants_currentdate(), sufr_system::timestamp(), and ymdhms2jd().

Here is the call graph for this function: