Comments (10)
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.
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.
Canceled because it won't add enough value (right now at least) for what I need this module for.
from hifitime.
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.
Great! I am also a bit busy but will put it on my list.
from hifitime.
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.
panicing would be an API change though since as_gregoriand_str
is infallible currently
from hifitime.
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.
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.
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)
- Add support for QZSS and IRNSS time scale HOT 2
- Export epoch formatters to Python
- Update MSRV to the version from 6 months ago
- Prefer `classmethod` over `staticmethod` for alternative constructors HOT 2
- Duration and Epoch serde to be human readable HOT 1
- [Documentation] Comparison with time and chrono crates? HOT 2
- Simplify Epoch initializations from time scales HOT 2
- Remove `der` dependency
- Display should print in Gregorian in the Epoch's time scale HOT 3
- MonthName from u8
- Refactor `Epoch` to keep track of a duration from time scale reference HOT 2
- Bug Report: Identified issues with arithmetic overflow, unreachable code, unwrap errors, and array out-of-bounds and so on HOT 9
- Improve error handling HOT 2
- Discovered errors including array out-of-bounds. HOT 1
- Epoch::from_format_str() does not set hours, minutes and seconds? HOT 4
- Python strftime time scale HOT 2
- Incorrect leap second handling when converting to UTC HOT 7
- Best way to create a UTC Epoch with precise year HOT 2
- from_gregorian but in GPST HOT 4
- jde_utc_days Error HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hifitime.