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

now() functionality for FixedOffest and a Utc::fixed_now() for DateTime w/ TimeZone (set to 0) #829

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd54d9c
Bump version to 0.5
esheppa Aug 27, 2022
4c351b1
Remove dependency on time 0.1
esheppa Aug 27, 2022
7344b5f
Remove support for rustc-serialize
esheppa Aug 27, 2022
112eb8b
Remove dependency on num-traits
esheppa Aug 27, 2022
c57fa03
Rename local Duration type to TimeDelta
esheppa Aug 27, 2022
947ce94
Add branch policy explanation to PR template
djc Aug 29, 2022
6e95b07
merge 0.4.x - Add/Sub days
esheppa Aug 30, 2022
f0aace9
Merge pull request #804 from chronotope/add-sub-days-from-0.4.x-v3
djc Aug 30, 2022
339d6fb
Support AIX's TZDB location
ecnelises Aug 30, 2022
5305023
Move the `datetime::serde` timestamp visitors into the respective mod…
nickelc Apr 5, 2022
925ca99
Add `parse_from_xxx` to `DateTime<Utc>`
mqudsi Aug 31, 2022
e491167
Update RFC 2822 and RFC 3339 docs
mqudsi Sep 8, 2022
4cfaf80
NaiveDateTime::from_timestamp_millis(_opt)
Pscheidl Sep 11, 2022
e2e651d
docs: Simplify documentation for NaiveDateTime::from_timestamp_millis
Pscheidl Sep 12, 2022
9212542
docs: prefix UNIX with `the`, remove whitespaces
Pscheidl Sep 12, 2022
49c4bad
fix: Negative UNIX timestamps accepted by `from_timestamp_millis`
Pscheidl Sep 14, 2022
40800ce
refactor: Use checked substitution & convert u32 conversiont to None …
Pscheidl Sep 18, 2022
6ed65a0
adding Utc::now() that returns a DateTime with timezone (=0)
epipheus Sep 28, 2022
0ef2fbe
from_utc_datetime needs a naive dt
epipheus Sep 28, 2022
0ef3160
from_utc_datetime needs a naive dt
epipheus Sep 28, 2022
3a49eb8
from_utc_datetime needs a naive dt
epipheus Sep 28, 2022
65fe6b5
from_utc_datetime needs a naive dt
epipheus Sep 28, 2022
100b336
impl Offset now method for FixedOffset
epipheus Sep 28, 2022
3eabd1f
fixed Offset now() method for FixedOffset
epipheus Sep 28, 2022
53b6a67
FixedOffset::now() from system time
epipheus Sep 28, 2022
f800708
utc::fixed_now() overloaded to Offset::now
epipheus Sep 28, 2022
42f752e
cargo fmt
epipheus Sep 28, 2022
7cd9586
now() need std to use system time
epipheus Sep 29, 2022
60cd6da
added back use DateTime
epipheus Sep 29, 2022
dda6435
ubuntu actions complain about use crate::{Date, DateTime} seperating …
epipheus Sep 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Thanks for contributing to chrono!

If your feature is semver-compatible, please target the 0.4.x branch;
the main branch will be used for 0.5.0 development going forward.

Please consider adding a test to ensure your bug fix/feature will not break in the future.
8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chrono"
version = "0.4.22"
version = "0.5.0-alpha.1"
description = "Date and time library for Rust"
homepage = "https://github.com/chronotope/chrono"
documentation = "https://docs.rs/chrono/"
Expand All @@ -20,22 +20,18 @@ appveyor = { repository = "chronotope/chrono" }
name = "chrono"

[features]
default = ["clock", "std", "oldtime", "wasmbind"]
default = ["clock", "std", "wasmbind"]
alloc = []
libc = []
std = []
clock = ["std", "winapi", "iana-time-zone"]
oldtime = ["time"]
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
__internal_bench = ["criterion"]
__doctest = []

[dependencies]
time = { version = "0.1.43", optional = true }
num-integer = { version = "0.1.36", default-features = false }
num-traits = { version = "0.2", default-features = false }
rustc-serialize = { version = "0.3.20", optional = true }
serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.5.2", optional = true }
criterion = { version = "0.3", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ test:

.PHONY: doc
doc: authors readme
cargo doc --features 'serde rustc-serialize bincode'
cargo doc --features 'serde bincode'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Date types are limited in about +/- 262,000 years from the common epoch.
Time types are limited in the nanosecond accuracy.

[Leap seconds are supported in the representation but
Chrono doesn't try to make use of them](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveTime.html#leap-second-handling).
Chrono doesn't try to make use of them](https://docs.rs/chrono/0.5/chrono/naive/struct.NaiveTime.html#leap-second-handling).
(The main reason is that leap seconds are not really predictable.)
Almost *every* operation over the possible leap seconds will ignore them.
Consider using `NaiveDateTime` with the implicit TAI (International Atomic Time) scale
Expand Down
2 changes: 1 addition & 1 deletion ci/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source "${BASH_SOURCE[0]%/*}/_shlib.sh"
TEST_TZS=(ACST-9:30 EST4 UTC0 Asia/Katmandu)
FEATURES=(std serde clock "alloc serde" unstable-locales)
CHECK_FEATURES=(alloc "std unstable-locales" "serde clock" "clock unstable-locales")
RUST_132_FEATURES=(rustc-serialize serde)
RUST_132_FEATURES=(serde)

main() {
if [[ "$*" =~ "-h" ]]; then
Expand Down
60 changes: 30 additions & 30 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::format::Locale;
use crate::format::{DelayedFormat, Item, StrftimeItems};
use crate::naive::{IsoWeek, NaiveDate, NaiveTime};
use crate::offset::{TimeZone, Utc};
use crate::oldtime::Duration as OldDuration;
use crate::time_delta::TimeDelta;
use crate::DateTime;
use crate::{Datelike, Weekday};

Expand Down Expand Up @@ -240,7 +240,7 @@ impl<Tz: TimeZone> Date<Tz> {
///
/// Returns `None` when it will result in overflow.
#[inline]
pub fn checked_add_signed(self, rhs: OldDuration) -> Option<Date<Tz>> {
pub fn checked_add_signed(self, rhs: TimeDelta) -> Option<Date<Tz>> {
let date = self.date.checked_add_signed(rhs)?;
Some(Date { date, offset: self.offset })
}
Expand All @@ -249,7 +249,7 @@ impl<Tz: TimeZone> Date<Tz> {
///
/// Returns `None` when it will result in overflow.
#[inline]
pub fn checked_sub_signed(self, rhs: OldDuration) -> Option<Date<Tz>> {
pub fn checked_sub_signed(self, rhs: TimeDelta) -> Option<Date<Tz>> {
let date = self.date.checked_sub_signed(rhs)?;
Some(Date { date, offset: self.offset })
}
Expand All @@ -260,7 +260,7 @@ impl<Tz: TimeZone> Date<Tz> {
/// This does not overflow or underflow at all,
/// as all possible output fits in the range of `Duration`.
#[inline]
pub fn signed_duration_since<Tz2: TimeZone>(self, rhs: Date<Tz2>) -> OldDuration {
pub fn signed_duration_since<Tz2: TimeZone>(self, rhs: Date<Tz2>) -> TimeDelta {
self.date.signed_duration_since(rhs.date)
}

Expand Down Expand Up @@ -483,43 +483,43 @@ impl<Tz: TimeZone> hash::Hash for Date<Tz> {
}
}

impl<Tz: TimeZone> Add<OldDuration> for Date<Tz> {
impl<Tz: TimeZone> Add<TimeDelta> for Date<Tz> {
type Output = Date<Tz>;

#[inline]
fn add(self, rhs: OldDuration) -> Date<Tz> {
fn add(self, rhs: TimeDelta) -> Date<Tz> {
self.checked_add_signed(rhs).expect("`Date + Duration` overflowed")
}
}

impl<Tz: TimeZone> AddAssign<OldDuration> for Date<Tz> {
impl<Tz: TimeZone> AddAssign<TimeDelta> for Date<Tz> {
#[inline]
fn add_assign(&mut self, rhs: OldDuration) {
fn add_assign(&mut self, rhs: TimeDelta) {
self.date = self.date.checked_add_signed(rhs).expect("`Date + Duration` overflowed");
}
}

impl<Tz: TimeZone> Sub<OldDuration> for Date<Tz> {
impl<Tz: TimeZone> Sub<TimeDelta> for Date<Tz> {
type Output = Date<Tz>;

#[inline]
fn sub(self, rhs: OldDuration) -> Date<Tz> {
fn sub(self, rhs: TimeDelta) -> Date<Tz> {
self.checked_sub_signed(rhs).expect("`Date - Duration` overflowed")
}
}

impl<Tz: TimeZone> SubAssign<OldDuration> for Date<Tz> {
impl<Tz: TimeZone> SubAssign<TimeDelta> for Date<Tz> {
#[inline]
fn sub_assign(&mut self, rhs: OldDuration) {
fn sub_assign(&mut self, rhs: TimeDelta) {
self.date = self.date.checked_sub_signed(rhs).expect("`Date - Duration` overflowed");
}
}

impl<Tz: TimeZone> Sub<Date<Tz>> for Date<Tz> {
type Output = OldDuration;
type Output = TimeDelta;

#[inline]
fn sub(self, rhs: Date<Tz>) -> OldDuration {
fn sub(self, rhs: Date<Tz>) -> TimeDelta {
self.signed_duration_since(rhs)
}
}
Expand All @@ -543,7 +543,7 @@ where
mod tests {
use super::Date;

use crate::oldtime::Duration;
use crate::time_delta::TimeDelta;
use crate::{FixedOffset, NaiveDate, Utc};

#[cfg(feature = "clock")]
Expand All @@ -555,15 +555,15 @@ mod tests {
const WEEKS_PER_YEAR: f32 = 52.1775;

// This is always at least one year because 1 year = 52.1775 weeks.
let one_year_ago = Utc::today() - Duration::weeks((WEEKS_PER_YEAR * 1.5).ceil() as i64);
let one_year_ago = Utc::today() - TimeDelta::weeks((WEEKS_PER_YEAR * 1.5).ceil() as i64);
// A bit more than 2 years.
let two_year_ago = Utc::today() - Duration::weeks((WEEKS_PER_YEAR * 2.5).ceil() as i64);
let two_year_ago = Utc::today() - TimeDelta::weeks((WEEKS_PER_YEAR * 2.5).ceil() as i64);

assert_eq!(Utc::today().years_since(one_year_ago), Some(1));
assert_eq!(Utc::today().years_since(two_year_ago), Some(2));

// If the given DateTime is later than now, the function will always return 0.
let future = Utc::today() + Duration::weeks(12);
let future = Utc::today() + TimeDelta::weeks(12);
assert_eq!(Utc::today().years_since(future), None);
}

Expand All @@ -573,20 +573,20 @@ mod tests {
let date = Date::<Utc>::from_utc(naivedate, Utc);
let mut date_add = date;

date_add += Duration::days(5);
assert_eq!(date_add, date + Duration::days(5));
date_add += TimeDelta::days(5);
assert_eq!(date_add, date + TimeDelta::days(5));

let timezone = FixedOffset::east(60 * 60);
let date = date.with_timezone(&timezone);
let date_add = date_add.with_timezone(&timezone);

assert_eq!(date_add, date + Duration::days(5));
assert_eq!(date_add, date + TimeDelta::days(5));

let timezone = FixedOffset::west(2 * 60 * 60);
let date = date.with_timezone(&timezone);
let date_add = date_add.with_timezone(&timezone);

assert_eq!(date_add, date + Duration::days(5));
assert_eq!(date_add, date + TimeDelta::days(5));
}

#[test]
Expand All @@ -597,8 +597,8 @@ mod tests {
let date = Local.from_utc_date(&naivedate);
let mut date_add = date;

date_add += Duration::days(5);
assert_eq!(date_add, date + Duration::days(5));
date_add += TimeDelta::days(5);
assert_eq!(date_add, date + TimeDelta::days(5));
}

#[test]
Expand All @@ -607,20 +607,20 @@ mod tests {
let date = Date::<Utc>::from_utc(naivedate, Utc);
let mut date_sub = date;

date_sub -= Duration::days(5);
assert_eq!(date_sub, date - Duration::days(5));
date_sub -= TimeDelta::days(5);
assert_eq!(date_sub, date - TimeDelta::days(5));

let timezone = FixedOffset::east(60 * 60);
let date = date.with_timezone(&timezone);
let date_sub = date_sub.with_timezone(&timezone);

assert_eq!(date_sub, date - Duration::days(5));
assert_eq!(date_sub, date - TimeDelta::days(5));

let timezone = FixedOffset::west(2 * 60 * 60);
let date = date.with_timezone(&timezone);
let date_sub = date_sub.with_timezone(&timezone);

assert_eq!(date_sub, date - Duration::days(5));
assert_eq!(date_sub, date - TimeDelta::days(5));
}

#[test]
Expand All @@ -631,7 +631,7 @@ mod tests {
let date = Local.from_utc_date(&naivedate);
let mut date_sub = date;

date_sub -= Duration::days(5);
assert_eq!(date_sub, date - Duration::days(5));
date_sub -= TimeDelta::days(5);
assert_eq!(date_sub, date - TimeDelta::days(5));
}
}
Loading