b2d(3f) - [M_time:BAS] given a BAS (Baseday and Seconds) returns a date-time array DAT. (LICENSE:MIT)
Synopsis
Description
Options
Returns
Example
Author
License
function b2d(bas) result(dat)
type(BAStime),intent(in),optional :: bas integer :: dat(8)
Converts a Baseday and Seconds (BAS) to a DAT date-time array.
bas A Baseday and seconds(MJD) is composed of whole days since the start of 17 Nov 1858 CE in Universal Time (UTC)
and an offset in seconds from the base day. If not present, use current time.
dat Integer array holding a "DAT" array, similar in structure to the array returned by the intrinsic DATE_AND_TIME(3f): dat=[ year,month,day,timezone,hour,& & minutes,seconds,milliseconds]
Sample program:
program demo_b2d use M_time, only : b2d, d2b, fmtdate, realtime, BAStime !BAStime includes operator(+), operator(-) implicit none integer,parameter :: dp=kind(0.0d0) type(BAStime) :: today type(BAStime) :: aday type(BAStime) :: newday, yesterday, tomorrow integer :: dat(8) character(len=*),parameter :: g=(*(g0,1x))Results:write(*,g)b2d: call date_and_time(values=dat) ! get the date using intrinsic today=d2b(dat) ! convert DAT to BAS aday=BAStime(1,0.0_dp) ! a value of one day write(*,g)Today=,fmtdate(b2d(today))
write(*,g)BAStime +- BAStime write(*,g)Yesterday=,fmtdate(b2d(today+BAStime(-1,0.0_dp))) write(*,g)Tomorrow= ,fmtdate(b2d(today+BAStime(+1,0.0_dp)))
write(*,g)Yesterday=,fmtdate(b2d(today+BAStime(0,-86400.0_dp))) write(*,g)Tomorrow= ,fmtdate(b2d(today+BAStime(0,+86400.0_dp)))
write(*,g)Yesterday=,fmtdate(b2d(today-aday)) write(*,g)Tomorrow= ,fmtdate(b2d(today+aday))
yesterday=today-aday write(*,g)Yesterday=,fmtdate(b2d(yesterday)) tomorrow=today+aday write(*,g)Tomorrow=,fmtdate(b2d(tomorrow))
write(*,g)BAStime +- value_in_seconds write(*,g)Yesterday=,fmtdate(b2d(today-86400)) write(*,g)Tomorrow= ,fmtdate(b2d(today+86400))
write(*,g)BAStime comparisons newday=today+(aday/2) write(*,g)today=,today%format() write(*,g)newday=,newday%format() call pr(today,newday) call pr(newday,today) call pr(today,today)
write(*,g)BAStime compound expressions write(*,g) (today+86400/2).eq.newday,fmtdate(b2d(newday)) contains subroutine pr(left,right) type(BAStime),intent(in) :: left, right write(*,g) eq,left.eq.right, & gt,left.gt.right, & lt,left.lt.right, & ge,left.ge.right, & le,left.le.right, & ne,left.ne.right end subroutine pr end program demo_b2d
> b2d: > Today= Monday, January 27th, 2025 7:52:40 AM UTC-05:00 > BAStime +- BAStime > Yesterday= Sunday, January 26th, 2025 7:52:40 AM UTC-05:00 > Tomorrow= Tuesday, January 28th, 2025 7:52:40 AM UTC-05:00 > Yesterday= Sunday, January 26th, 2025 7:52:40 AM UTC-05:00 > Tomorrow= Tuesday, January 28th, 2025 7:52:40 AM UTC-05:00 > Yesterday= Sunday, January 26th, 2025 7:52:40 AM UTC-05:00 > Tomorrow= Tuesday, January 28th, 2025 7:52:40 AM UTC-05:00 > Yesterday= Sunday, January 26th, 2025 7:52:40 AM UTC-05:00 > Tomorrow= Tuesday, January 28th, 2025 7:52:40 AM UTC-05:00 > BAStime +- value_in_seconds > Yesterday= Sunday, January 26th, 2025 7:52:40 AM UTC-05:00 > Tomorrow= Tuesday, January 28th, 2025 7:52:40 AM UTC-05:00 > BAStime comparisons > today= Monday, January 27th, 2025 7:52:40 AM UTC-05:00 > newday= Monday, January 27th, 2025 7:52:40 PM UTC-05:00 > eq F gt F lt T ge F le T ne T > eq F gt T lt F ge T le F ne T > eq T gt F lt F ge T le T ne F > BAStime compound expressions > T Monday, January 27th, 2025 7:52:40 PM UTC-05:00
John S. Urban, 2025
Nemo Release 3.1 | b2d (3) | February 23, 2025 |