Skip to content

DateTime function to convert to time.Time value (close #115)#116

Merged
icholy merged 3 commits intoadrianmo:masterfrom
mholt:master
Aug 8, 2024
Merged

DateTime function to convert to time.Time value (close #115)#116
icholy merged 3 commits intoadrianmo:masterfrom
mholt:master

Conversation

@mholt
Copy link
Copy Markdown
Contributor

@mholt mholt commented Aug 2, 2024

This change adds a DateTime function as discussed in #115.

icholy
icholy previously approved these changes Aug 3, 2024
@icholy icholy requested a review from aldas August 3, 2024 03:51
@icholy
Copy link
Copy Markdown
Collaborator

icholy commented Aug 4, 2024

@aldas are you ok with this API?

aldas
aldas previously approved these changes Aug 4, 2024
Copy link
Copy Markdown
Collaborator

@aldas aldas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only thing here I'm not sure is - should referenceYear be first parameter as it is optional and d and t are "main" things here we are combining but they come after "optional" parameter.

but I trust you more than myself when it comes to creating designing reasonable APIs.

so LGTM

@mholt mholt dismissed stale reviews from aldas and icholy via c607125 August 4, 2024 20:31
@mholt
Copy link
Copy Markdown
Contributor Author

mholt commented Aug 4, 2024

That's a valid point; I guess it's more conventional to have optional arguments last. Refactored and pushed :)

@mholt mholt requested review from aldas and icholy August 5, 2024 21:40
aldas
aldas previously approved these changes Aug 6, 2024
@icholy
Copy link
Copy Markdown
Collaborator

icholy commented Aug 8, 2024

They sorry for the delay, I haven't had access to my computer for the past couple days.

should referenceYear be first parameter as it is optional and d and t are "main" things here we are combining but they come after "optional" parameter.

The referenceYear parameter isn't optional though, it must be explicitly passed every time. If Go did support optional parameters then putting it last would make sense because you'd be able to omit it at the call site.

nmea.DateTime(d, t)

I put the referenceYear first because it's the most significant unit. It's roughly modeled after time.Date signature which follows the same left to right pattern.

func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time

I won't die on this hill though. @mholt care to be the tie breaker on this?

@mholt
Copy link
Copy Markdown
Contributor Author

mholt commented Aug 8, 2024

I guess we technically could do func DateTime(d Date, t Time, referenceYear ...int) time.Time to make it optional.

But I think your point about "most significant unit" is a good one, and I like the parity with time.Date. Century, year, time. Or put another way: First two year digits, last 2 year digits and rest of date, time.

It's also probably best for this value to be explicitly set. Psychologically speaking, having it be the first argument may be a good way to encourage that.

I just switched it back.

@icholy icholy merged commit af41c6a into adrianmo:master Aug 8, 2024
@mholt
Copy link
Copy Markdown
Contributor Author

mholt commented Aug 8, 2024

Thank you both!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants