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¶
- Enter a
tryblock wrapping the entire parse. (BR-031) - Split the input on the trimmed delimiter's characters.
- If more than one part is present, parse part 1 as the end date and set
hasEndDate = true. - If at least one part is present, parse part 0 as the begin date.
- Return a two-date
DateRangewhen an end date was found, otherwise a begin-date-onlyDateRange(whoseEndDatedefaults toDateTime.MaxValue). (BR-032) - 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)"])
Related documentation¶
Sources¶
Common/SAIF.Common/Classes/DateRange.cs