-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add startTime and endTime in OffsetDateTime format #9
Conversation
/** | ||
* Returns {@link OffsetDateTime} from the {@link ConditionMatchResult#startTimeMillis}. | ||
*/ | ||
public OffsetDateTime startTime() { | ||
return Instant.ofEpochMilli(startTimeMillis).atZone(ZoneId.systemDefault()).toOffsetDateTime(); | ||
} |
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.
Thanks for the great suggestion! In my opinion, this method is not necessary. Because the conversion from milliseconds to OffsetDateTime doesn't have to be done here. Because developers using Conditional can do it themselves. What do you think of using the method below??
private static String millisAsISO8601String(long millis) {
return Instant.ofEpochMilli(millis).atZone(ZoneId.systemDefault()).toOffsetDateTime().toString();
}
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.
So, summarize your opinion...
ConditionMatchResult.startTimeMillis
,ConditionMatchResult.endTimeMillis
properties remain aslong
type as before.ConditionMatchResult.toString()
outputsstartTime
andendTime
inOffsetDateTime
format.
This seems like a good way. The values for startTime
and endTime
can be obtained through the public methods startTimeMillis()
and endTimeMillis()
, and We can know that the returned values are milliseconds through these method names, so users can return them as appropriate Date objects as needed 🙂
However, I think it is something to consider about the mismatch between the type provided in the log(OffsetDateTime
) and the type actually provided(long
).
Also, to use OffsetDateTime
, the user must separately call the same method(you suggested) used to convert long to OffsetDateTime
inside ConditionMatchResult
.
So, if there's conversion from long
to OffsetDateTime
inside ConditionMatchResult.toString()
, I think it's okay to add this value as a field and provide it for use as a public method.
What do you think?
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.
It seems we don't have to provide a public method to convert from Milliseconds -> OffsetDateTime. Because we need ZoneId or ZoneOffset to convert from Milliseconds to OffsetDateTime. Then, we need to receive ZoneId or ZoneOffset as parameter, which is no different from converting Milliseconds -> OffsetDateTime directly by the developer.
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.
Thank you for your kind explanation.
As you said, it seems more reasonable to provide the millisecond information as before, and let the user use this to get the necessary Date object.
I'll fix on it based on what you commented on 🙂
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 applied the way you suggested at 0fa5717 🙂
.append(", startTimeMillis=").append(millisAsString(startTimeMillis)) | ||
.append(", endTimeMillis=").append(millisAsString(endTimeMillis)) |
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.
If startTime and endTime are displayed in ISO-8601 format, it would be good to remove startTimeMillis and endTimeMillis.
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.
Same as #9 (comment)
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.
Great work! Thank you for your contribution!
Motivation:
Modifications:
startTime
andendTime
inOffsetDateTime
formatResult:
ConditionMatchResult
, you can check theOffsetDateTime
type value similarly to the way you check thestartTime
andendTime
.Additional info:
startTime
andendTime
in milliseconds is the intended function please comment 🙂