Skip to content

Commit

Permalink
drop millis
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 17, 2021
1 parent 7ccc925 commit 1db393d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 66 deletions.
10 changes: 5 additions & 5 deletions polars/polars-time/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Bounds {

impl Display for Bounds {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let start = timestamp_ns_to_datetime(*self.start);
let stop = timestamp_ns_to_datetime(*self.stop);
let start = timestamp_ns_to_datetime(self.start);
let stop = timestamp_ns_to_datetime(self.stop);
write!(f, "Bounds: {} -> {}", start, stop)
}
}
Expand All @@ -34,15 +34,15 @@ impl Bounds {

/// Duration in nanoseconcds for this Boundary
pub fn duration(&self) -> TimeNanoseconds {
(*self.stop - *self.start).into()
self.stop - self.start
}

pub fn is_empty(&self) -> bool {
*self.stop == *self.start
self.stop == self.start
}

// check if nanoseconds is within bounds
pub fn is_member(&self, t: i64) -> bool {
t >= *self.start && t < *self.stop
t >= self.start && t < self.stop
}
}
14 changes: 2 additions & 12 deletions polars/polars-time/src/duration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::calendar::{
is_leap_year, last_day_of_month, timestamp_ns_to_datetime, NS_MINUTE, NS_SECONDS,
};
use crate::unit::{TimeMilliseconds, TimeNanoseconds};
use crate::unit::TimeNanoseconds;
use chrono::{Datelike, NaiveDate, NaiveDateTime, NaiveTime, Timelike};
use std::ops::{Add, Mul};

Expand Down Expand Up @@ -123,7 +123,7 @@ impl Add<Duration> for TimeNanoseconds {
/// Adds a duration to a nanosecond timestamp

fn add(self, rhs: Duration) -> Self {
let t = *self;
let t = self;
let d = rhs;
let mut new_t = t;

Expand Down Expand Up @@ -183,16 +183,6 @@ impl Add<Duration> for TimeNanoseconds {
}
}

impl Add<Duration> for TimeMilliseconds {
type Output = Self;

/// Adds a duration to a nanosecond timestamp

fn add(self, rhs: Duration) -> Self {
self.to_nsecs().add(rhs).to_millisecs()
}
}

fn nsecs_timestamp_to_datetime(ts: i64) -> NaiveDateTime {
let secs = ts / 1_000_000_000;
let nsec = ts % 1_000_000_000;
Expand Down
46 changes: 1 addition & 45 deletions polars/polars-time/src/unit.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
use std::ops::Deref;

#[derive(Copy, Clone, Debug)]
pub struct TimeNanoseconds(pub i64);

impl Deref for TimeNanoseconds {
type Target = i64;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl From<i64> for TimeNanoseconds {
fn from(v: i64) -> Self {
TimeNanoseconds(v)
}
}

#[derive(Copy, Clone, Debug)]
pub struct TimeMilliseconds(i64);

impl Deref for TimeMilliseconds {
type Target = i64;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl From<i64> for TimeMilliseconds {
fn from(v: i64) -> Self {
TimeMilliseconds(v)
}
}

impl TimeNanoseconds {
pub fn to_millisecs(self) -> TimeMilliseconds {
(*self / 1000_0000).into()
}
}

impl TimeMilliseconds {
pub fn to_nsecs(self) -> TimeNanoseconds {
(*self * 1000_0000).into()
}
}
pub type TimeNanoseconds = i64;
8 changes: 4 additions & 4 deletions polars/polars-time/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Window {
}

pub fn truncate(&self, t: TimeNanoseconds) -> TimeNanoseconds {
self.every.truncate_nanoseconds(*t).into()
self.every.truncate_nanoseconds(t)
}

/// returns the bounds for the earliest window bounds
Expand All @@ -41,8 +41,8 @@ impl Window {
}

pub(crate) fn estimate_overlapping_bounds(&self, boundary: Bounds) -> usize {
(*boundary.duration() / *self.every.duration()
+ *self.period.duration() / *self.every.duration()) as usize
(boundary.duration() / self.every.duration()
+ self.period.duration() / self.every.duration()) as usize
}

pub fn get_overlapping_bounds(&self, boundary: Bounds) -> Vec<Bounds> {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Iterator for BoundsIter {
type Item = Bounds;

fn next(&mut self) -> Option<Self::Item> {
if *self.bi.start < *self.boundary.stop {
if self.bi.start < self.boundary.stop {
let out = self.bi;
self.bi.start = self.bi.start + self.window.every;
self.bi.stop = self.bi.stop + self.window.every;
Expand Down

0 comments on commit 1db393d

Please sign in to comment.