Convert a Julian date string to a DateTime¶
Decode a Julian-format date string into a DateTime, triggered when caller decodes a Julian-formatted date from a fixed-format interchange file*.
| Field | Value |
|---|---|
| Operation ID | OP-007 |
| Trigger | Caller decodes a Julian-formatted date from a fixed-format interchange file* |
| Inputs | julian (e.g. 25001, 2025001), optional millenium |
| Outputs | DateTime |
| Primary components | SAIF.Common.Julian.ToDate(string julian, int millenium = 0) |
| Entry point | Common/SAIF.Common/Classes/Julian.cs |
Steps¶
- Call
IsValid(julian, out message); that overload converts the string toInt32inside a try/catch (returningfalseon conversion failure), then requires the numeric form to have more than 3 digits. (BR-022, BR-023) - If invalid, throw
ApplicationException(message)— either "The julian must contain at least 4 numbers" or an empty message when the numeric conversion failed. (BR-022, BR-023) - Call
GetYear(julian, out isLeapYear, millenium)(OP-008) to resolve the calendar year and its leap status. (BR-024, BR-025) - Set the valid day count to 366 for a leap year, otherwise 365. (BR-025)
- Parse the last three characters of the input as the day-of-year.
- If the day-of-year exceeds the valid day count, throw
ApplicationException("The julian day must be < {validDaysInYear}."). (BR-026) - Return
new DateTime(year, 1, 1).AddDays(dayOfYear - 1).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([ToDate called]) --> S1["Call IsValid(julian,<br>out message)"]
S1 --> D1{"Julian string<br>valid?"}
D1 -->|No| Err1(["Throw ApplicationException<br>with validation message"])
D1 -->|Yes| S2["Call GetYear to resolve<br>year and leap status"]
S2 --> D2{"Is leap<br>year?"}
D2 -->|Yes| S3a["Set valid day<br>count to 366"]
D2 -->|No| S3b["Set valid day<br>count to 365"]
S3a --> S4
S3b --> S4["Parse last three chars<br>as day-of-year"]
S4 --> D3{"Day-of-year exceeds<br>valid day count?"}
D3 -->|Yes| Err2(["Throw ApplicationException:<br>invalid julian day"])
D3 -->|No| S5["Compute DateTime(year,1,1)<br>.AddDays(dayOfYear - 1)"]
S5 --> End([Return DateTime])
Related documentation¶
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
Common/SAIF.Common/Classes/Julian.cs