Skip to content

Commit

Permalink
Remove some deprecation warnings, make the code easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
locka99 committed Jul 28, 2023
1 parent 2a79d67 commit a5f452a
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/src/types/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
str::FromStr,
};

use chrono::{Datelike, Duration, SecondsFormat, TimeZone, Timelike, Utc};
use chrono::{Duration, SecondsFormat, TimeZone, Timelike, Utc};
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};

use crate::types::encoding::*;
Expand Down Expand Up @@ -153,16 +153,8 @@ impl From<(u16, u16, u16, u16, u16, u16, u32)> for DateTime {
impl From<DateTimeUtc> for DateTime {
fn from(date_time: DateTimeUtc) -> Self {
// OPC UA date time is more granular with nanos, so the value supplied is made granular too
let year = date_time.year();
let month = date_time.month();
let day = date_time.day();
let hour = date_time.hour();
let minute = date_time.minute();
let second = date_time.second();
let nanos = (date_time.nanosecond() / NANOS_PER_TICK as u32) * NANOS_PER_TICK as u32;
let date_time = Utc
.ymd(year, month, day)
.and_hms_nano(hour, minute, second, nanos);
let date_time = date_time.with_nanosecond(nanos).unwrap();
DateTime { date_time }
}
}
Expand Down

0 comments on commit a5f452a

Please sign in to comment.