Skip to content
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

Timestamp construction capability #5

Open
lpil opened this issue Dec 31, 2024 · 2 comments
Open

Timestamp construction capability #5

lpil opened this issue Dec 31, 2024 · 2 comments

Comments

@lpil
Copy link
Member

lpil commented Dec 31, 2024

We need to be able to give people a way to construct timestamp.

What might these APIs look like?

  • year, month of year, day of month, hour of day, minute of hour, second of minute, offset

Is this what we'd want? Are they functions with that many parameters? What types would each value be?

Implementation references

@mooreryan
Copy link

mooreryan commented Jan 2, 2025

I thought it would be a nice test case for qcheck to generate values for the parse_rfc3339 function, and realized it has not been implemented yet. So I went ahead and implemented one. In the course of that, I have seen the need for a sort of from_date_time function that returns timestamps from the parts of the rfc3339 formatted string, (year, month, day, hour, min, second, fraction, offset). So a function like from_date_time, which takes those parts, may be appropriate in a public interface if the time module as well.

@dzuk-mutant
Copy link

dzuk-mutant commented Jan 5, 2025

Thinking about my own use cases, I'd probably use time stamp construction from a user input point of view as on the backend I keep to Unix time as much as possible as well as simpler ones for testing internally.

Here are some thoughts I had:

Offset ones that would be handy for user input.

  • from_date_offset(year:, month:, date:, offset:,) Making an offset timestamp equivalent to 00:00:00 on that day in the given offset, for working out what the start of the day in a user's given timezone would be,
  • from_date_time_offset(year:, month:, date:, minute:, second:, offset:,) Making Timestamp at the specific date time, combined with the user's current offset.

Ones for quickly throwing together Timestamps for internal testing.

  • from_date(year:, month:, date:,) for constructing a timestamp that is equivalent to 00:00:00 on that day in UTC.
  • from_date_time(year:, month:, date:, minute:, second:,) for constructing a Timestamp at the given day and time in UTC.
  • Functions like date.literal() in gtempo which will crash the application if the given input is wrong but really handy for quickly making time values in unit tests without having to handle Results.

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

No branches or pull requests

3 participants