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

Add a date library #21

Open
sparkprime opened this issue Nov 6, 2014 · 7 comments
Open

Add a date library #21

sparkprime opened this issue Nov 6, 2014 · 7 comments

Comments

@sparkprime
Copy link
Collaborator

Code to convert to/from tuples like {year: x, month:x, ... seconds: x } into textual / other structured representations (seconds since epoch, etc).

@sparkprime
Copy link
Collaborator Author

@oconnorr

@oconnorr
Copy link
Contributor

Do you want the Jsonnet output to be dependent on or independent of the contents of the Olson time zone database that happens to be installed on the local system?

If independent, then you cannot do date/time conversions based on time zone (you are restricted to using UTC offsets), but you could write it in Jsonnet.

If dependent, then Jsonnet isn't hermetic and some operations need to be built-in.

@sparkprime
Copy link
Collaborator Author

I can't remember who initially suggested this or what they wanted it for. But, yes I think it would have to be UTC and static offsets only, otherwise it would no-longer be hermetic.

@davidzchen
Copy link
Member

Could we make use of cctz for this?

@oconnorr
Copy link
Contributor

Using cctz, or any other tool for dealing with civil time, would make Jsonnet output dependent on the contents of /usr/share/zoneinfo whose content varies from machine to machine and from month to month.

@simonrouse9461
Copy link

Any update on this?

@daniel-falk
Copy link

daniel-falk commented Oct 12, 2024

+1 on this! It would be great to be able to parse dates, compare time and date and calculate time differences. It does not / should not depend on the system timezone in my opinion, but it would be good if it has a built-in calendar so it understands conversion between different time zones. I would like to be able to do tasks such such as:

OBS: hypothetical example

local cert_config = {
  issueDate: "2024-10-12T12:42:31.144210+02:00",
  durationDays: 30,
};

{
  // Calculate issue time as UTC
  local issueDate = std.timeParse(cert_config.issueDate),
  issueDate: std.timeFormat(issueDate, tz="UTC"),
  // Calculate the expiration date
  local endDate = std.timeAdd(issueDate, days=cert_config.durationDays),
  endDate: std.timeFormat(endDate, tz="UTC"),
  // Alert a week before expiration
  alertDate: std.timeFormat(std.addTime(endDate, days=-7), tz="UTC"),
  // Calculate the duration in seconds
  validForSeconds: std.timeDiffConvert(std.timeDiff(endDate, issueDate), unit="seconds"),
}

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

No branches or pull requests

5 participants