C Library Functions  - b2d (3)

NAME

b2d(3f) - [M_time:BAS] given a BAS (Baseday and Seconds) returns a date-time array DAT. (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Returns
Example
Author
License

SYNOPSIS

function b2d(bas) result(dat)

    type(BAStime),intent(in),optional :: bas
    integer                           :: dat(8)

DESCRIPTION

Converts a Baseday and Seconds (BAS) to a DAT date-time array.

OPTIONS

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.

RETURNS

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]

EXAMPLE

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))’

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

Results:

    > 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

AUTHOR

John S. Urban, 2025

LICENSE

    MIT


Nemo Release 3.1 b2d (3) February 23, 2025
Generated by manServer 1.08 from 6f05b9ac-bc8d-4fa4-8433-e7d6140a0c75 using man macros.