diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 36570d11..69d88cb9 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,4 +1,4 @@ -# This file is autogenerated by maturin v0.14.17 +# This file is autogenerated by maturin v1.3.2 # To update, run # # maturin generate-ci --pytest -o .github/workflows/python.yml github @@ -28,14 +28,27 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' - name: Build wheels uses: PyO3/maturin-action@v1 with: target: ${{ matrix.target }} args: --release --out dist --find-interpreter -F python - sccache: 'true' manylinux: auto + before-script-linux: | + # If we're running on rhel centos, install needed packages. + if command -v yum &> /dev/null; then + yum update -y && yum install -y perl-core openssl openssl-devel pkgconfig libatomic + + # If we're running on i686 we need to symlink libatomic + # in order to build openssl with -latomic flag. + if [[ ! -d "/usr/lib64" ]]; then + ln -s /usr/lib/libatomic.so.1 /usr/lib/libatomic.so + fi + else + # If we're running on debian-based system. + apt update -y && apt-get install -y libssl-dev openssl pkg-config + fi - name: Upload wheels uses: actions/upload-artifact@v3 with: @@ -74,7 +87,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' architecture: ${{ matrix.target }} - name: Build wheels uses: PyO3/maturin-action@v1 @@ -105,7 +118,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -156,4 +169,4 @@ jobs: MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: command: upload - args: --skip-existing * + args: --non-interactive --skip-existing * diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e8d4a7e6..2ee7e22d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,7 +33,7 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] rust: - - { version: "1.64", name: MSRV } + - { version: "1.70", name: MSRV } - { version: stable, name: stable } runs-on: ${{ matrix.os }} diff --git a/Cargo.toml b/Cargo.toml index 382c5f05..38ad281e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hifitime" -version = "3.8.2" +version = "3.8.6" authors = ["Christopher Rabotin "] description = "Ultra-precise date and time handling in Rust for scientific applications with leap second support" homepage = "https://nyxspace.com/" @@ -18,16 +18,36 @@ crate-type = ["cdylib", "rlib"] name = "hifitime" [dependencies] -serde = {version = "1.0.155", optional = true} -serde_derive = {version = "1.0.155", optional = true} -der = {version = "0.6.1", features = ["derive", "real"], optional = true} -pyo3 = { version = "0.19.0", features = ["extension-module"], optional = true } -num-traits = {version = "0.2.15", default-features = false, features = ["libm"]} -lexical-core = {version = "0.8.5", default-features = false, features = ["parse-integers", "parse-floats"]} -reqwest = { version = "0.11", features = ["blocking", "json"], optional = true} -tabled = {version = "0.12.0", optional = true} +serde = { version = "1.0.155", optional = true } +serde_derive = { version = "1.0.155", optional = true } +der = { version = "0.6.1", features = ["derive", "real"], optional = true } +pyo3 = { version = "0.20.0", features = ["extension-module"], optional = true } +num-traits = { version = "0.2.15", default-features = false, features = [ + "libm", +] } +lexical-core = { version = "0.8.5", default-features = false, features = [ + "parse-integers", + "parse-floats", +] } +reqwest = { version = "0.11", features = ["blocking", "json"], optional = true } +tabled = { version = "0.14.0", optional = true } openssl = { version = "0.10", features = ["vendored"], optional = true } +[target.wasm32-unknown-unknown.dependencies] +js-sys = { version = "0.3"} +wasm-bindgen_rs = { package = "wasm-bindgen", version = "0.2"} +web-sys = { version = "0.3", features = ['Window', 'Performance', 'PerformanceTiming'] } + +[target.wasm32-unknown-emscripten.dependencies] +js-sys = { version = "0.3"} +wasm-bindgen_rs = { package = "wasm-bindgen", version = "0.2"} +web-sys = { version = "0.3", features = ['Window', 'Performance', 'PerformanceTiming'] } + +[target.asmjs-unknown-emscripten.dependencies] +js-sys = { version = "0.3"} +wasm-bindgen_rs = { package = "wasm-bindgen", version = "0.2"} +web-sys = { version = "0.3", features = ['Window', 'Performance', 'PerformanceTiming'] } + [dev-dependencies] serde_json = "1.0.91" criterion = "0.5.1" @@ -42,7 +62,7 @@ ut1 = ["std", "reqwest", "tabled", "openssl"] [[bench]] name = "crit_epoch" -harness = false +harness = false [[bench]] name = "crit_duration" diff --git a/README.md b/README.md index ea93d2cb..3f57bbe3 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ In Python: [![hifitime on crates.io][cratesio-image]][cratesio] [![hifitime on docs.rs][docsrs-image]][docsrs] -[![minimum rustc: 1.64](https://img.shields.io/badge/minimum%20rustc-1.64-yellowgreen?logo=rust)](https://www.whatrustisit.com) +[![minimum rustc: 1.70](https://img.shields.io/badge/minimum%20rustc-1.70-yellowgreen?logo=rust)](https://www.whatrustisit.com) [![Build Status](https://github.com/nyx-space/hifitime/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/nyx-space/hifitime/actions) [![Build Status](https://github.com/nyx-space/hifitime/actions/workflows/formal_verification.yml/badge.svg?branch=master)](https://github.com/nyx-space/hifitime/actions) [![codecov](https://codecov.io/gh/nyx-space/hifitime/branch/master/graph/badge.svg?token=l7zU57rUGs)](https://codecov.io/gh/nyx-space/hifitime) @@ -309,6 +309,12 @@ In order to provide full interoperability with NAIF, hifitime uses the NAIF algo # Changelog +## 3.8.5 + +Changes from 3.8.2 are only dependency upgrades until this release. + +Minimum Supported Rust version bumped from 1.64 to **1.70**. + ## 3.8.2 + Clarify README and add a section comparing Hifitime to `time` and `chrono`, cf. [#221](https://github.com/nyx-space/hifitime/issues/221) + Fix incorrect printing of Gregorian dates prior to to 1900, cf. [#204](https://github.com/nyx-space/hifitime/issues/204) diff --git a/examples/python/basic.py b/examples/python/basic.py index c2e48209..a1523842 100644 --- a/examples/python/basic.py +++ b/examples/python/basic.py @@ -1,6 +1,6 @@ """ * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/examples/python/timescales.py b/examples/python/timescales.py index 162e40a9..a3011178 100644 --- a/examples/python/timescales.py +++ b/examples/python/timescales.py @@ -1,6 +1,6 @@ """ * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/pyproject.toml b/pyproject.toml index fd60678d..16607264 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=0.13,<0.14"] +requires = ["maturin>=1.3,<1.4"] build-backend = "maturin" [project] @@ -15,4 +15,4 @@ classifiers = [ [tool.yapf] based_on_style = "google" spaces_before_comment = 4 -column_limit = 100 \ No newline at end of file +column_limit = 100 diff --git a/src/asn1der.rs b/src/asn1der.rs index 0e3e7731..73a41088 100644 --- a/src/asn1der.rs +++ b/src/asn1der.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/deprecated.rs b/src/deprecated.rs index 4b6e3685..40da9311 100644 --- a/src/deprecated.rs +++ b/src/deprecated.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/duration.rs b/src/duration.rs index d733ac5f..43260d88 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. @@ -730,15 +730,23 @@ impl Duration { } #[cfg(feature = "python")] - fn __richcmp__(&self, other: Self, op: CompareOp) -> bool { - match op { - CompareOp::Lt => *self < other, - CompareOp::Le => *self <= other, - CompareOp::Eq => *self == other, - CompareOp::Ne => *self != other, - CompareOp::Gt => *self > other, - CompareOp::Ge => *self >= other, - } + fn __le__(&self, other: Self) -> bool { + *self <= other + } + + #[cfg(feature = "python")] + fn __lt__(&self, other: Self) -> bool { + *self < other + } + + #[cfg(feature = "python")] + fn __ge__(&self, other: Self) -> bool { + *self >= other + } + + #[cfg(feature = "python")] + fn __gt__(&self, other: Self) -> bool { + *self > other } // Python constructors diff --git a/src/efmt/consts.rs b/src/efmt/consts.rs index 020795f2..3c2f21e4 100644 --- a/src/efmt/consts.rs +++ b/src/efmt/consts.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/efmt/format.rs b/src/efmt/format.rs index 4333eb44..e1819dab 100644 --- a/src/efmt/format.rs +++ b/src/efmt/format.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. @@ -309,7 +309,14 @@ impl Format { }; let epoch = match day_of_year { - Some(days) => Epoch::from_day_of_year(decomposed[0], days, ts), + Some(days) => { + // Parse the elapsed time in the given day + let elapsed = (decomposed[3] as i64) * Unit::Hour + + (decomposed[4] as i64) * Unit::Minute + + (decomposed[5] as i64) * Unit::Second + + (decomposed[6] as i64) * Unit::Nanosecond; + Epoch::from_day_of_year(decomposed[0], days, ts) + elapsed + } None => Epoch::maybe_from_gregorian( decomposed[0], decomposed[1].try_into().unwrap(), @@ -522,3 +529,11 @@ fn epoch_format_from_str() { let fmt = Format::from_str("%a, %d %b %Y %H:%M:%S").unwrap(); assert_eq!(fmt, crate::efmt::consts::RFC2822); } + +#[cfg(feature = "std")] +#[test] +fn gh_248_regression() { + let e = Epoch::from_format_str("2023-117T12:55:26", "%Y-%jT%H:%M:%S").unwrap(); + + assert_eq!(format!("{e}"), "2023-04-28T12:55:26 UTC"); +} diff --git a/src/efmt/formatter.rs b/src/efmt/formatter.rs index 3922910a..922a85ad 100644 --- a/src/efmt/formatter.rs +++ b/src/efmt/formatter.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/efmt/mod.rs b/src/efmt/mod.rs index 8f193283..cc0e9f8f 100644 --- a/src/efmt/mod.rs +++ b/src/efmt/mod.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/epoch.rs b/src/epoch.rs index b86020f4..3ba44ee8 100644 --- a/src/epoch.rs +++ b/src/epoch.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. @@ -44,8 +44,6 @@ use crate::leap_seconds_file::LeapSecondsFile; use serde_derive::{Deserialize, Serialize}; use core::str::FromStr; -#[cfg(feature = "std")] -use std::time::SystemTime; #[cfg(not(feature = "std"))] use num_traits::{Euclid, Float}; @@ -676,6 +674,12 @@ impl Epoch { ) } + #[must_use] + /// Initialize an Epoch from the provided duration since UTC midnight 1970 January 01. + pub fn from_unix_duration(duration: Duration) -> Self { + Self::from_utc_duration(UNIX_REF_EPOCH.to_utc_duration() + duration) + } + #[must_use] /// Initialize an Epoch from the provided UNIX second timestamp since UTC midnight 1970 January 01. pub fn from_unix_seconds(seconds: f64) -> Self { @@ -2933,12 +2937,11 @@ impl Epoch { impl Epoch { /// Initializes a new Epoch from `now`. /// WARNING: This assumes that the system time returns the time in UTC (which is the case on Linux) - /// Uses [`std::time::SystemTime::now`](https://doc.rust-lang.org/std/time/struct.SystemTime.html#method.now) under the hood + /// Uses [`std::time::SystemTime::now`](https://doc.rust-lang.org/std/time/struct.SystemTime.html#method.now) + /// or javascript interop under the hood pub fn now() -> Result { - match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { - Ok(std_duration) => Ok(Self::from_unix_seconds(std_duration.as_secs_f64())), - Err(_) => Err(Errors::SystemTimeError), - } + let duration = crate::system_time::duration_since_unix_epoch()?; + Ok(Self::from_unix_duration(duration)) } } diff --git a/src/errors.rs b/src/errors.rs index a7eb91c2..473b05dc 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/leap_seconds.rs b/src/leap_seconds.rs index 54687c6b..a02f166d 100644 --- a/src/leap_seconds.rs +++ b/src/leap_seconds.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/leap_seconds_file.rs b/src/leap_seconds_file.rs index a0a1dd46..efbad593 100644 --- a/src/leap_seconds_file.rs +++ b/src/leap_seconds_file.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/lib.rs b/src/lib.rs index 46e80fe8..74020118 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. @@ -141,3 +141,6 @@ pub mod python; #[cfg(feature = "std")] extern crate core; + +#[cfg(feature = "std")] +mod system_time; diff --git a/src/month.rs b/src/month.rs index b0f7d984..8837daec 100644 --- a/src/month.rs +++ b/src/month.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/parser.rs b/src/parser.rs index 78e498d9..7a4b4828 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/python.rs b/src/python.rs index ca95994d..abbee374 100644 --- a/src/python.rs +++ b/src/python.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/system_time.rs b/src/system_time.rs new file mode 100644 index 00000000..03d656b2 --- /dev/null +++ b/src/system_time.rs @@ -0,0 +1,22 @@ +use crate::{Duration, Errors}; + +#[cfg(target_arch = "wasm32")] +pub(crate) fn duration_since_unix_epoch() -> Result { + { + use crate::Unit; + use wasm_bindgen_rs::prelude::*; + js_sys::Reflect::get(&js_sys::global(), &JsValue::from_str("performance")) + .map_err(|_| Errors::SystemTimeError) + .map(|performance| { + performance.unchecked_into::().now() * Unit::Second + }) + } +} + +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn duration_since_unix_epoch() -> Result { + std::time::SystemTime::now() + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .map_err(|_| Errors::SystemTimeError) + .and_then(|d| d.try_into().map_err(|_| Errors::SystemTimeError)) +} diff --git a/src/timescale.rs b/src/timescale.rs index 22ab3a82..39bbe52d 100644 --- a/src/timescale.rs +++ b/src/timescale.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/timeseries.rs b/src/timeseries.rs index bc53f8ae..d04fded5 100644 --- a/src/timeseries.rs +++ b/src/timeseries.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/timeunits.rs b/src/timeunits.rs index fc535b60..ac6ef850 100644 --- a/src/timeunits.rs +++ b/src/timeunits.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/ut1.rs b/src/ut1.rs index e88afb46..bf3a3606 100644 --- a/src/ut1.rs +++ b/src/ut1.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/src/weekday.rs b/src/weekday.rs index fe3be0fd..484f3acf 100644 --- a/src/weekday.rs +++ b/src/weekday.rs @@ -1,6 +1,6 @@ /* * Hifitime, part of the Nyx Space tools - * Copyright (C) 2022 Christopher Rabotin et al. (cf. AUTHORS.md) + * Copyright (C) 2023 Christopher Rabotin et al. (cf. AUTHORS.md) * This Source Code Form is subject to the terms of the Apache * v. 2.0. If a copy of the Apache License was not distributed with this * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. diff --git a/tests/python/test_epoch.py b/tests/python/test_epoch.py index 0e2c7265..1e39c8f6 100644 --- a/tests/python/test_epoch.py +++ b/tests/python/test_epoch.py @@ -1,4 +1,4 @@ -from hifitime import Epoch, TimeSeries, Unit +from hifitime import Epoch, TimeSeries, Unit, Duration from datetime import datetime @@ -22,7 +22,7 @@ def test_utcnow(): dt = datetime.utcnow() # Hifitime uses a different clock to Python and print down to the nanosecond - assert dt.isoformat()[:21] == f"{epoch}"[:21] + assert dt.isoformat()[:20] == f"{epoch}"[:20] def test_time_series(): @@ -44,3 +44,14 @@ def test_time_series(): print(f"#{num}:\t{epoch}") assert num == 10 + +def test_duration_eq(): + """ + Checks that Duration comparisons work + """ + + assert Unit.Second * 0.0 == Duration("0 ns") + assert Unit.Second * 1.0 >= Duration("0 ns") + assert Unit.Second * 1.0 > Duration("0 ns") + assert Duration("0 ns") <= Unit.Second * 1.0 + assert Duration("0 ns") < Unit.Second * 1.0 \ No newline at end of file diff --git a/tests/ut1.rs b/tests/ut1.rs index 2934e883..2f6a29c4 100644 --- a/tests/ut1.rs +++ b/tests/ut1.rs @@ -46,6 +46,6 @@ fn test_ut1_from_jpl() { let ut1_epoch = epoch.to_ut1(provider); assert_eq!( format!("{:x}", ut1_epoch), - "2022-01-03T03:05:06.679020600 TAI", + "2022-01-03T03:05:43.789100000 TAI", ); }