Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR sees the introduction of 3 new public date types for a total of
4 date types. In parentheses is the game that a particular date can
handle.
Previously
Date
was only implemented which required copy+pasted withslight tweaks for the HOI4 module.
The same would have been needed for Stellaris. Maintaining separate date
implementations would require any bugs or improvements to be copied
around which I would be susceptible to forgetting.
This PR creates the
RawDate
which the 3 other date types are basedaround. A
RawDate
is space optimized so that even dates with hours(eg: HOI4) still consume 32 bits. And while a
RawDate
can handle anydate format it has the least validation and won't check if the number of
days in a given month makes sense. That is why it is recommended to use
the date type of the data you are parsing. The
RawDate
is stillpublicly exposed for the times when parsing dates with unknown origins.
And instead of exposing that all dates are based around the raw date, a
PdsDate
trait was introduced that allows one to query a dates year,month, and day just in case the internals need to be switched out again.
There is a breaking change in the API introduced with this PR. The new
API should feel more like chrono. The thought was that it is better to
conform to existing rust date APIs instead of reinventing:
Date::new
replaced withDate::from_ymd_opt
which emulateschrono's:
NaiveDate::from_ymd_opt
Date::from_ymd
which is a panicing version offrom_ymd_opt
which should allow better creation ergonomics for constant dates and
emulates chrono's:
NaiveDate::from_ymd
Date::parse_from_str
replaced withDate::parse
which takes a byteslice instead and returns a result.
FromStr
so one can do"1444.11.11".parse::<Date>()
.Chrono dates also implement
FromStr
Hash
much like chrono dates.Date::from_binary
keeps the same return API to match chrono'sNaiveDateTime::from_timestamp_opt
Date::game_fmt
andDate::iso_8601
now return an intermediateobject instead of an allocated string, much like chrono's
NaiveDateTime::format
Additional changes:
Date::to_binary
now returns what the date would look like whenencoded in the binary format.
component is used and only dates with zero hours will be detected as
dates.