parse_date Function

public pure function parse_date(datestring) result(fields)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: datestring

Return Value type(date_fields)


Calls

proc~~parse_date~~CallsGraph proc~parse_date parse_date proc~is_valid_date~2 is_valid_date proc~parse_date->proc~is_valid_date~2 proc~read_whole_number read_whole_number proc~parse_date->proc~read_whole_number proc~undelimit undelimit proc~parse_date->proc~undelimit proc~get_month_end get_month_end proc~is_valid_date~2->proc~get_month_end proc~is_between is_between proc~is_valid_date~2->proc~is_between proc~is_valid_month is_valid_month proc~is_valid_date~2->proc~is_valid_month proc~is_valid_year is_valid_year proc~is_valid_date~2->proc~is_valid_year proc~read_whole_number_indexed read_whole_number_indexed proc~read_whole_number->proc~read_whole_number_indexed proc~get_month_ends get_month_ends proc~get_month_end->proc~get_month_ends proc~is_valid_month->proc~is_between proc~is_valid_year->proc~is_between proc~get_integer_digit_from_string get_integer_digit_from_string proc~read_whole_number_indexed->proc~get_integer_digit_from_string proc~is_whole_number is_whole_number proc~read_whole_number_indexed->proc~is_whole_number proc~get_integer_digit get_integer_digit proc~get_integer_digit_from_string->proc~get_integer_digit proc~is_leap_year~2 is_leap_year proc~get_month_ends->proc~is_leap_year~2

Called by

proc~~parse_date~~CalledByGraph proc~parse_date parse_date proc~construct_iso8601date construct_ISO8601Date proc~construct_iso8601date->proc~parse_date proc~test_parse_date~2 test_parse_date proc~test_parse_date~2->proc~parse_date interface~iso8601date ISO8601Date interface~iso8601date->proc~construct_iso8601date

Source Code

   pure function parse_date(datestring) result(fields)
      character(len=*), intent(in) :: datestring
      type(date_fields) :: fields
      integer, parameter :: LENGTH = 8
      character, parameter :: DELIMITER = '-'
      integer, parameter :: YEAR_POSITION = 1
      integer, parameter :: MONTH_POSITION = 5
      integer, parameter :: DAY_POSITION = 7
      character(len=LENGTH) :: undelimited

      ! Eliminate delimiters so that there is one parsing block
      undelimited=undelimit(datestring, DELIMITER)

      if(len(undelimited) == LENGTH) then
         fields%year_ = read_whole_number(undelimited(YEAR_POSITION:MONTH_POSITION-1))
         fields%month_ = read_whole_number(undelimited(MONTH_POSITION:DAY_POSITION-1))
         fields%day_ = read_whole_number(undelimited(DAY_POSITION:LENGTH))
         fields%is_valid_ = is_valid_date(fields)
      else
         fields%is_valid_ = .FALSE.
      end if

   end function parse_date