Skip to content

Parse a delimited date-range string into a DateRange

Parse a delimited string back into a DateRange, defaulting on any failure, triggered when caller round-trips a DateRange.ToString() value.

Field Value
Operation ID OP-013
Trigger Caller round-trips a DateRange.ToString() value
Inputs date, delimiter
Outputs DateRange
Primary components SAIF.Common.DateRange.Parse(string date, string delimiter = "-")
Entry point Common/SAIF.Common/Classes/DateRange.cs

Steps

  1. Enter a try block wrapping the entire parse. (BR-031)
  2. Split the input on the trimmed delimiter's characters.
  3. If more than one part is present, parse part 1 as the end date and set hasEndDate = true.
  4. If at least one part is present, parse part 0 as the begin date.
  5. Return a two-date DateRange when an end date was found, otherwise a begin-date-only DateRange (whose EndDate defaults to DateTime.MaxValue). (BR-032)
  6. On any exception, swallow it and return a default DateRange() — i.e. MinValue..MaxValue. (BR-031)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["Parse(date, delimiter) called"]) --> Try["Enter try block"]
    Try --> Split["Split input on trimmed<br>delimiter's characters"]
    Split --> Check1{"More than one part?"}
    Check1 -->|Yes| ParseEnd["Parse part 1 as end date;<br>set hasEndDate = true"]
    Check1 -->|No| Check2
    ParseEnd --> Check2{"At least one part?"}
    Check2 -->|Yes| ParseBegin["Parse part 0 as begin date"]
    Check2 -->|No| Decide
    ParseBegin --> Decide{"hasEndDate is true?"}
    Decide -->|Yes| TwoDate(["Return two-date DateRange"])
    Decide -->|No| OneDate(["Return begin-date-only<br>DateRange (EndDate = MaxValue)"])
    Try -.->|"On exception"| Catch(["Swallow exception; return<br>default DateRange (MinValue..MaxValue)"])

Sources

  • Common/SAIF.Common/Classes/DateRange.cs