Context: jweir#19
Could we replace the existing Model
with something that more closely represents the same things as the ISO 8601 spec?
E.g.:
type Model =
Model Iso8601Base
type alias Iso8601Base =
{ offsetInMinutes : Maybe Int
, date : Iso8601DateOption
, time : Maybe Iso8601TimeOption
}
{-| Note that a "Year" may differ based on the representation.
For example, 2019-12-30 and 2020-W01-01 are the same date.
So while all members of this sum type share a Year, they're not
freely interchangeable.
-}
type Iso8601DateOption
= YearMonthDay Int Int Int -- 1999-12-31
| Year Int -- 1999
| YearWeek Int Int -- 1999-W52
| YearWeekDay Int Int Int -- 1999-W52-7
| YearOrdinal Int Int -- 1999-354
type Iso8601TimeOption
= Hour Int (Maybe Float) -- 09, 09.5
| HourMinute Int Int (Maybe Float) -- 09:59, 09:59.5
| HourMinuteSecond Int Int Int (Maybe Float) -- 09:59:59, 09:59:59.999
Model
isn't an opaque type, so immediately there'll be a major version bump.
Would it necessarily mean a large amount of work? For those relying on the default values, would a function like Model -> {offset: Int, seconds:Int, ...}
be enough?
Other parts of ISO 8601 to consider
- Durations
- Time intervals
- Repeating intervals
Precedents
.Net apparently had a similar situation with their DateTime
type, which they addressed by adding a three-state "Kind" (either Local, UTC, or Unknown) to the existing type, and creating a new DateTimeOffset
type which enforces Absolute (un-ambiguous) times.