anchor.diff:    ! ARGUMENTS:
     TYPE(datetime),INTENT(IN) :: d0,d1
   
  -  eq = d0 % year        == d1 % year   .AND. &
  -       d0 % month       == d1 % month  .AND. &
  -       d0 % day         == d1 % day    .AND. &
  -       d0 % hour        == d1 % hour   .AND. &
  -       d0 % minute      == d1 % minute .AND. &
  -       d0 % second      == d1 % second .AND. &
  -       d0 % millisecond == d1 % millisecond
  +  TYPE(datetime) :: d0_utc,d1_utc
  +
  +  ! Convert to UTC before making comparison
  +  d0_utc = d0 % utc()
  +  d1_utc = d1 % utc()
  +
  +  eq = d0_utc % year        == d1_utc % year   .AND. &
  +       d0_utc % month       == d1_utc % month  .AND. &
  +       d0_utc % day         == d1_utc % day    .AND. &
  +       d0_utc % hour        == d1_utc % hour   .AND. &
  +       d0_utc % minute      == d1_utc % minute .AND. &
  +       d0_utc % second      == d1_utc % second .AND. &
  +       d0_utc % millisecond == d1_utc % millisecond
   
   ENDFUNCTION eq
   !======================================================================>
  
positive.code: PURE ELEMENTAL REAL(KIND=real_dp) FUNCTION date2num(d)
  !======================================================================>
  !
  ! Given a datetime instance d, returns number of days
  ! since 0001-01-01 00:00:00.
  !
  !======================================================================>
  
    ! ARGUMENTS:
    TYPE(datetime),INTENT(IN) :: d
  
    INTEGER :: year
  
    ! d%year must be positive:
    IF(d % year < 1)THEN
      date2num = 0
      RETURN
    ENDIF
  
    date2num = 0
    DO year = 1,d % year-1
      date2num = date2num+daysInYear(year)
    ENDDO
  
    date2num = date2num+d % yearday()+d % hour*h2d+d % minute*m2d&
              +(d % second+1d-3*d % millisecond)*s2d
   
  ENDFUNCTION date2num
  !======================================================================>
  
negative.code:   ! ARGUMENTS:
    TYPE(datetime),INTENT(IN) :: d0,d1
  
    TYPE(datetime) :: d0_utc,d1_utc
  
    ! Convert to UTC before making comparison
    d0_utc = d0 % utc()
    d1_utc = d1 % utc()
  
    ! Year comparison block
    IF(d0_utc % year > d1_utc % year)THEN
      gt = .TRUE.
    ELSEIF(d0_utc % year < d1_utc % year)THEN
      gt = .FALSE.
    ELSE
  
      ! Month comparison block
      IF(d0_utc % month > d1_utc % month)THEN
        gt = .TRUE.
      ELSEIF(d0_utc % month < d1_utc % month)THEN
        gt = .FALSE.
      ELSE
  
        ! Day comparison block
        IF(d0_utc % day > d1_utc % day)THEN
          gt = .TRUE.
        ELSEIF(d0_utc % day < d1_utc % day)THEN
          gt = .FALSE.
        ELSE
  
          ! Hour comparison block
          IF(d0_utc % hour > d1_utc % hour)THEN
            gt = .TRUE.
          ELSEIF(d0_utc % hour < d1_utc % hour)THEN
            gt = .FALSE.
          ELSE
  
            ! Minute comparison block
            IF(d0_utc % minute > d1_utc % minute)THEN
              gt = .TRUE.
            ELSEIF(d0_utc % minute < d1_utc % minute)THEN
              gt = .FALSE.
            ELSE
  
              ! Second comparison block
              IF(d0_utc % second > d1_utc % second)THEN
                gt = .TRUE.
              ELSEIF(d0_utc % second < d1_utc % second)THEN
                gt = .FALSE.
              ELSE
  
                ! Millisecond comparison block
                IF(d0_utc % millisecond > d1_utc % millisecond)THEN
                  gt = .TRUE.
                ELSE
                  gt = .FALSE.
  