Git Product home page Git Product logo

Comments (10)

mkolopanis avatar mkolopanis commented on August 16, 2024 1

I've been finding a lot of use for this crate in some astronomy work and initializing from unix could be really useful. I'm happy make a PR for this if you're still interested in the functionality.

from hifitime.

mkolopanis avatar mkolopanis commented on August 16, 2024 1

I think my question more stems from the fact I view UNIX as a time format like GPS seconds which aren't implemented as a full TimeSystem.
It can definitely be converted to a valid gregorian date, but UNIX isn't really a time scale like UTC from my understanding instead it's duration from a different epoch relative to UTC.

Originally I was only thinking about making function to convert to and from Durations since the unix epoch, but the use of TimeSystem gave me pause.

it's pretty easy to define a function like which gives the number of seconds for an Epoch since the UNIX epoch (01 JAN 1970 00:00:00 UTC)

    ///Returns the Duration since the UNIX epoch UTC midnight 01 Jan 1970.
    pub fn as_unix_duration(self) -> Duration {
        let cnt = self.get_num_leap_seconds();
        // TAI = UNIX + leap_seconds + UNIX_OFFSET_UTC_SECONDS <=> UNIX = TAI - leap_seconds - UNIX_OFFSET_UTC_SECONDS
        self.0 + i64::from(-cnt) * Unit::Second - UNIX_OFFSET_UTC_SECONDS * Unit::Second
    }

but the gregorian representation would just be the iso 8601 in whichever time scale you prefer.

Maybe it'll be easier to compare if I open the PR and it can be seen side by side but you are welcome to look at what I've added so far in my fork too.
https://github.com/mkolopanis/hifitime/blob/5972911a7ef9808a0f39f79d4eadd30cc55d74a8/src/epoch.rs

from hifitime.

ChristopherRabotin avatar ChristopherRabotin commented on August 16, 2024

Canceled because it won't add enough value (right now at least) for what I need this module for.

from hifitime.

ChristopherRabotin avatar ChristopherRabotin commented on August 16, 2024

Great to hear! Yes, that would be very useful! I'd be happy to review your work, I'm currently quite a bit busy on another project that uses hifitime that's why I haven't reopened this issue recently although I now see the value again.

from hifitime.

mkolopanis avatar mkolopanis commented on August 16, 2024

Great! I am also a bit busy but will put it on my list.

from hifitime.

mkolopanis avatar mkolopanis commented on August 16, 2024

Adding UNIX as a full TimeSystem brought up a question about gregorian strings.

Since UNIX timestamps are usually just listed in gregorian dates as UTC, would you prefer to automatically output to UTC in as_gregorian_str or to error?

from hifitime.

mkolopanis avatar mkolopanis commented on August 16, 2024

panicing would be an API change though since as_gregoriand_str is infallible currently

from hifitime.

ChristopherRabotin avatar ChristopherRabotin commented on August 16, 2024

In which cases can a unix timestamp not be converted to a valid gregorian date? Do you have some code I could look at? I'm not that familiar with UNIX timestamps to UTC conversions, so in my mind it should work out of the box.

from hifitime.

ChristopherRabotin avatar ChristopherRabotin commented on August 16, 2024

I see, thanks for the explanation.

I think you are right that UNIX isn't a time scale / time system like TT since UNIX is just a seconds representation of the UTC time.

In the code you linked to, everything looks fine: where do you envision a function panicking?

from hifitime.

mkolopanis avatar mkolopanis commented on August 16, 2024

I think there shouldn't be any new panics introduced actually at this point if we both agree about it as a full TimeSystem. I'll open the PR and you can have a full look.

from hifitime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.