pulumi / pulumi-std

Standard library functions implemented as a native Pulumi provider to be consumed from all Pulumi supported languages
Apache License 2.0
2 stars 2 forks source link

Add time functions to convert RFC3999 timestamps to Unix format and vice versa #57

Open SayakMukhopadhyay opened 1 month ago

SayakMukhopadhyay commented 1 month ago

This PR has been moved here from pulumi/pulumi-yaml#576 based on the discussion on this comment.

OP: Some providers outputs unix timestamps and some other RFC 3339 where some providers input unix and others RFC 3339 and I need to convert between the 2 formats when passing outputs to inputs. I am using YAML only as I want to keep using declarative syntax. Hence, based on the discussion I had in the community slack (ref: https://pulumi-community.slack.com/archives/C037PV12W6L/p1715335945150989) with @t0yv0 .

Please note that for now, I have only implemented one of the 2 functions I want to implement to check with you folks if I am going in the right direction.

I have implemented both the functions.

github-actions[bot] commented 1 month ago

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

github-actions[bot] commented 1 month ago

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

github-actions[bot] commented 1 month ago

PR is now waiting for a maintainer to take action.

Note for the maintainer: Commands available:

SayakMukhopadhyay commented 1 month ago

@Frassle , I am in a bit of a dilemma regarding the seconds precision that I should allow in these functions. RFC3999 allows fractional seconds but Unix time itself is seconds precision. It is possible to have millisecond, microsecond or nanosecond precision Unix time but that means I will have to ensure that the user inputs the precision I am asking, even adding 0's at the end if their unix time is only in seconds.

I am torn between allowing more than seconds precision as a lot of systems support millisecond unix time and I have seen a lot of RFC3999 times with millisecond fractions. But then, why stick at millisecond when modern systems can handle up to nanoseconds.

I fact, I can see even more issues. Imagine my functions only allow nanoseconds as UNIX input and output. If another resource outputs or needs an input of the time in milliseconds, I will need to do a math conversion, which I don't know if its possible in YAML. Even if it's possible, it creates a dangerous point of failure as if the other resource suddenly changes its schema to seconds instead of milliseconds, my mathematical operation can point to a totally different instance in time.

Or I can just keep things to spec and only handle unix seconds...