Skip to content

Commit

Permalink
Update examples in README
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarral committed May 11, 2024
1 parent 0a57383 commit 3d64811
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,38 @@ let gps_t1: GpsTime = t1.to_tai_time().unwrap();
println!("GPS timestamp: {}s, {}ns", gps_t1.as_secs(), gps_t1.subsec_nanos());
```

Conversion to and from date-time representations:
Construction from date-time fields and date-time strings:

```rust
use tai_time::{MonotonicTime, Tai1958Time};

let t0 = MonotonicTime::try_from_date_time(2222, 11, 11, 12, 34, 56, 789000000).unwrap();
// The `FromStr` implementation accepts date-time stamps with the format:
// [±][Y]...[Y]YYYY-MM-DD hh:mm:ss[.d[d]...[d]]
// or:
// [±][Y]...[Y]YYYY-MM-DD'T'hh:mm:ss[.d[d]...[d]]
let t0 = MonotonicTime::try_from_date_time(2222, 11, 11, 12, 34, 56, 789000000).unwrap();
assert_eq!("2222-11-11 12:34:56.789".parse(), Ok(t0));
```

Formatted display as date-time:

```rust
use tai_time::MonotonicTime;
let t0 = MonotonicTime::try_from_date_time(1234, 12, 13, 14, 15, 16, 123456000).unwrap();
assert_eq!(
format!("{}", t0),
"1234-12-13 14:15:16.123456"
);
assert_eq!(
format!("{:.0}", t0),
"1234-12-13 14:15:16"
);
assert_eq!(
format!("{:.3}", t0),
"1234-12-13 14:15:16.123"
);
assert_eq!(
Tai1958Time::new(0, 123456789).unwrap().to_string(),
"1958-01-01 00:00:00.123456789"
format!("{:.9}", t0),
"1234-12-13 14:15:16.123456000"
);
```

Expand Down

0 comments on commit 3d64811

Please sign in to comment.