-
Notifications
You must be signed in to change notification settings - Fork 69
Parsing of MJD and JD literals #1362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
astronomy/date_time_body.hpp
Outdated
operator""_Date(str, index_of(str, size, 'T')), | ||
operator""_Time(str + index_of(str, size, 'T') + 1, | ||
size - (index_of(str, size, 'T') + 1))).checked()); | ||
size >= 2 && str[0] == 'J' && str[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
str[1] == 'D'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a death test for that (and other formatting errors).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still testing a character as a boolean.
astronomy/date_time_body.hpp
Outdated
operator""_Time(str + index_of(str, size, 'T') + 1, | ||
size - (index_of(str, size, 'T') + 1))).checked()); | ||
size >= 2 && str[0] == 'J' && str[1] | ||
? contains(str, size - 1, '.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this means that the parser doesn't support something like "MJD1729."
. Is that correct? In any case, please comment to specify precisely what format is allowed, as is done for ISO dates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
TEST_F(TimeScalesTest, ModifiedJulianDate) { | ||
EXPECT_THAT("MJD0.0"_TT, Eq("1858-11-17T00:00:00"_TT)); | ||
EXPECT_THAT("MJD55200.0000"_TT, Eq("2010-01-04T00:00:00.000"_TT)); | ||
EXPECT_THAT("MJD55200.00000142361"_TT, Eq("2010-01-04T00:00:00.123"_TT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this implementation, nothing prevents MJD and JD from being used with UTC, which poses problems. I would not bother with supporting the ERFA quasi-JD convention, let's simply disallow those for UTC. That also makes it well-defined to go through Time
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
astronomy/date_time.hpp
Outdated
|
||
// If |time()| is 24:00:00, returns an equivalent DateTime where midnight is | ||
// expressed as 00:00:00 on the next day; otherwise, returns |*this|. | ||
constexpr DateTime normalized_end_of_day() const; | ||
|
||
private: | ||
constexpr DateTime(Date date, Time time); | ||
constexpr DateTime(Date date, Time time, bool iso); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment the semantics of the iso
parameter/member/accessor.
astronomy/date_time_body.hpp
Outdated
operator""_Date(str, index_of(str, size, 'T')), | ||
operator""_Time(str + index_of(str, size, 'T') + 1, | ||
size - (index_of(str, size, 'T') + 1))).checked()); | ||
size >= 2 && str[0] == 'J' && str[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still testing a character as a boolean.
astronomy/date_time.hpp
Outdated
@@ -84,27 +76,51 @@ class DateTime final { | |||
|
|||
constexpr Date const& date() const; | |||
constexpr Time const& time() const; | |||
// Returns true iff the object was constructed from an ISO 8601 string. | |||
constexpr bool iso() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or from BeginningOfDay
... Really what we care about in UTC is that it's not constructed from JD or MJD, not that it's constructed from an ISO 8601 string. Switch to jd()
(which also encompasses any variants, including MJD).
No description provided.