test_convert_to_ISO8601DateTime Subroutine

public subroutine test_convert_to_ISO8601DateTime()

Arguments

None

Calls

proc~~test_convert_to_iso8601datetime~~CallsGraph proc~test_convert_to_iso8601datetime test_convert_to_ISO8601DateTime assertequal assertequal proc~test_convert_to_iso8601datetime->assertequal assertfalse assertfalse proc~test_convert_to_iso8601datetime->assertfalse convert_to_iso8601datetime convert_to_iso8601datetime proc~test_convert_to_iso8601datetime->convert_to_iso8601datetime

Source Code

   subroutine test_convert_to_ISO8601DateTime()
      character(len=*), parameter :: cf_datetime_string_A = '2023-04-23 21:05:37'
      character(len=*), parameter :: expected_A = '2023-04-23T21:05:37'
      character(len=*), parameter :: cf_datetime_string_B= '2023-04-23 21:05:37.337'
      character(len=*), parameter :: expected_B = '2023-04-23T21:05:37.337'
      character(len=*), parameter :: undelimited_datetime_string_C = '20230423210537'
      character(len=*), parameter :: fail_D = '2023-4-23 21:05:37'
      character(len=*), parameter :: fail_E = '2023-04-23 21:5:37'
      character(len=:), allocatable :: output
      character(len=MAX_LEN) :: actual
      integer :: status

      call convert_to_ISO8601DateTime(cf_datetime_string_A, output, rc = status)
      @assertEqual(status, 0, 'Conversion A failed: ' // trim(cf_datetime_string_A))
      actual = trim(output)
      @assertEqual(expected_A, trim(actual), 'Datetime strings do not match.')

      call convert_to_ISO8601DateTime(cf_datetime_string_B, output, rc = status)
      @assertEqual(status, 0, 'Conversion B failed: ' // trim(cf_datetime_string_B))
      actual = trim(output)
      @assertEqual(expected_B, trim(actual), 'Datetime strings do not match.')

      call convert_to_ISO8601DateTime(undelimited_datetime_string_C, output, rc = status)
      @assertEqual(status, 0, 'Conversion C failed: ' // trim(undelimited_datetime_string_C))
      actual = trim(output)
      @assertEqual(expected_A, trim(actual), 'Datetime strings do not match.')

      call convert_to_ISO8601DateTime(fail_D, output, rc = status)
      @assertFalse(status == 0, 'Failed to catch illegal value - D')

      call convert_to_ISO8601DateTime(fail_E, output, rc = status)
      @assertFalse(status == 0, 'Failed to catch illegal value - E.')

   end subroutine test_convert_to_ISO8601DateTime