Skip to content

Commit

Permalink
Merge pull request #55 from hoodie/feature/maintenance
Browse files Browse the repository at this point in the history
refactor: stop using deprecated chrono methods
  • Loading branch information
hoodie authored Nov 13, 2022
2 parents cd97732 + 21e7b70 commit 1b3165b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
.push(
// add an all-day event
Event::new()
.all_day(NaiveDate::from_ymd(2016, 3, 15))
.all_day(NaiveDate::from_ymd_opt(2016, 3, 15).unwrap())
.summary("My Birthday")
.description("Hey, I'm gonna have a party\nBYOB: Bring your own beer.\nHendrik")
.done(),
Expand Down
14 changes: 10 additions & 4 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ mod tests {

#[test]
fn get_date_times_naive() {
let naive_date_time = NaiveDate::from_ymd(2001, 3, 13).and_hms(14, 15, 16);
let naive_date_time = NaiveDate::from_ymd_opt(2001, 3, 13)
.unwrap()
.and_hms_opt(14, 15, 16)
.unwrap();
let event = Event::new()
.starts(naive_date_time)
.ends(naive_date_time)
Expand All @@ -368,7 +371,7 @@ mod tests {

#[test]
fn get_date_times_utc() {
let utc_date_time = Utc.ymd(2001, 3, 13).and_hms(14, 15, 16);
let utc_date_time = Utc.with_ymd_and_hms(2001, 3, 13, 14, 15, 16).unwrap();
let event = Event::new()
.timestamp(utc_date_time)
.starts(utc_date_time)
Expand All @@ -381,7 +384,10 @@ mod tests {

#[test]
fn get_date_times_tzid() {
let date_time = NaiveDate::from_ymd(2001, 3, 13).and_hms(14, 15, 16);
let date_time = NaiveDate::from_ymd_opt(2001, 3, 13)
.unwrap()
.and_hms_opt(14, 15, 16)
.unwrap();
let date_time_tzid = CalendarDateTime::WithTimezone {
date_time,
tzid: "Pacific/Auckland".to_string(),
Expand All @@ -396,7 +402,7 @@ mod tests {

#[test]
fn get_dates_naive() {
let naive_date = NaiveDate::from_ymd(2001, 3, 13);
let naive_date = NaiveDate::from_ymd_opt(2001, 3, 13).unwrap();
let event = Event::new().starts(naive_date).ends(naive_date).done();
assert_eq!(event.get_start(), Some(naive_date.into()));
assert_eq!(event.get_end(), Some(naive_date.into()));
Expand Down
11 changes: 7 additions & 4 deletions src/components/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod tests {

#[test]
fn get_properties_set() {
let completed = Utc.ymd(2001, 3, 13).and_hms(14, 15, 16);
let completed = Utc.with_ymd_and_hms(2001, 3, 13, 14, 15, 16).unwrap();
let todo = Todo::new()
.percent_complete(42)
.status(TodoStatus::NeedsAction)
Expand All @@ -110,14 +110,17 @@ mod tests {

#[test]
fn get_date_times_naive() {
let naive_date_time = NaiveDate::from_ymd(2001, 3, 13).and_hms(14, 15, 16);
let naive_date_time = NaiveDate::from_ymd_opt(2001, 3, 13)
.unwrap()
.and_hms_opt(14, 15, 16)
.unwrap();
let todo = Todo::new().due(naive_date_time).done();
assert_eq!(todo.get_due(), Some(naive_date_time.into()));
}

#[test]
fn get_date_times_utc() {
let utc_date_time = Utc.ymd(2001, 3, 13).and_hms(14, 15, 16);
let utc_date_time = Utc.with_ymd_and_hms(2001, 3, 13, 14, 15, 16).unwrap();
let todo = Todo::new()
.due(utc_date_time)
.completed(utc_date_time)
Expand All @@ -128,7 +131,7 @@ mod tests {

#[test]
fn get_dates_naive() {
let naive_date = NaiveDate::from_ymd(2001, 3, 13);
let naive_date = NaiveDate::from_ymd_opt(2001, 3, 13).unwrap();
let todo = Todo::new().due(naive_date).done();
assert_eq!(todo.get_due(), Some(naive_date.into()));
}
Expand Down
9 changes: 5 additions & 4 deletions tests/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ END:VCALENDAR\r
#[test]
fn test_calendar_to_string() {
let mut calendar = Calendar::new();
let cest_date = FixedOffset::east(2 * 3600)
.ymd(2014, 7, 8)
.and_hms(9, 10, 11);
let utc_date = Utc.ymd(2014, 7, 9).and_hms(9, 10, 11);
let cest_date = FixedOffset::east_opt(2 * 3600)
.unwrap()
.with_ymd_and_hms(2014, 7, 8, 9, 10, 11)
.unwrap();
let utc_date = Utc.with_ymd_and_hms(2014, 7, 9, 9, 10, 11).unwrap();
let event = Event::new()
.status(EventStatus::Tentative)
.starts(cest_date.with_timezone(&Utc))
Expand Down
4 changes: 2 additions & 2 deletions tests/try_into_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::convert::TryInto;
#[test]
fn try_into_string() -> Result<(), Box<dyn std::error::Error>> {
let bday = Event::new()
.starts(NaiveDate::from_ymd(2016, 3, 15))
.ends(NaiveDate::from_ymd(2016, 3, 15))
.starts(NaiveDate::from_ymd_opt(2016, 3, 15).unwrap())
.ends(NaiveDate::from_ymd_opt(2016, 3, 15).unwrap())
.summary("My Birthday")
.description(
r#"Hey, I'm gonna have a party
Expand Down

0 comments on commit 1b3165b

Please sign in to comment.