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

Time and Duration support? #19

Closed
natefinch opened this issue Oct 11, 2017 · 9 comments
Closed

Time and Duration support? #19

natefinch opened this issue Oct 11, 2017 · 9 comments

Comments

@natefinch
Copy link
Collaborator

I know bazel's skylark eschews time functions because they want to ensure reproducibility in their configurations, but this implementation of skylark seems like it could be used for so much more, and at least having access to official skylark time and duration types would keep implementations compatible that otherwise would not be, if consumers all create their own implementations.

Even purely from a configuration standpoint, I could definitely see wanting to be able to specify durations for timeouts, or timestamps for expiration dates, etc.

@alandonovan
Copy link
Contributor

Yes, if Skylark were to have a standard library, time & date would be an obvious first package. For now I suggest you experiment with the package interface you want, and later we can discuss how to share it with others.

@natefinch
Copy link
Collaborator Author

cool.

FYI, I have a helper wrapper I'm working on here: https://godoc.org/github.com/hippogryph/skyhook

It's mostly just a convenience wrapper using reflection to avoid boilerplate.

I'm happy to make a helper library for use with time values.

@natefinch
Copy link
Collaborator Author

time implementation coming along here: https://github.com/hippogryph/time

@natefinch
Copy link
Collaborator Author

So, a question on APIs ... are we going for the same API as python, i.e. everything should work as in https://docs.python.org/2/library/datetime.html transparently?

@alandonovan
Copy link
Contributor

alandonovan commented Oct 12, 2017

Don't copy Python---they've got it wrong so many times. I would use the Go API as a starting point, something like this:

module time

functions
        duration(string) duration                               # parse a duration
        location(string) location                               # parse a location
        time(string, format=..., location=...) time             # parse a time
        now() time # implementations would be able to make this a constant
        zero time # a constant

type duration
operators
        duration - time = duration
        duration + time = time
        duration == duration
        duration < duration
fields
        hours float
        minutes float
        nanoseconds int
        seconds float

type time
operators
        time == time
        time < time  
        time + duration = time
        time - duration = time
        time - time = duration
fields
        year int
        month int
        day int
        hour int
        minute int
        second int
        nanosecond int

TODO:
- unix time_t conversions
- timezone stuff
- strftime formatting
- constructor from 6 components + location

alandonovan referenced this issue in google/skylark Oct 5, 2018
Work in progress

Fixes #17

Change-Id: Ia4bd6b28b24168d996dc5f159a05d2b153e1fede
@alandonovan
Copy link
Contributor

alandonovan commented Oct 5, 2018

I don't have time to work on this but I thought I would share where I got to in case anyone wants to borrow from it:
https://github.com/google/skylark/tree/wip-skylark-time/skylarktime

@b5

@alandonovan alandonovan transferred this issue from google/skylark Nov 21, 2018
@srebhan
Copy link

srebhan commented Mar 11, 2021

@alandonovan this should be solved by the recently added time support.

@srebhan
Copy link

srebhan commented Apr 16, 2024

@adonovan this issue can be closed as https://github.com/google/starlark-go/tree/master/lib/time exists now.

@adonovan
Copy link
Collaborator

Indeed it can. Many thanks for this contribution!

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

4 participants