Skip to content

Commit

Permalink
fix and improve dateparser's examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollie Ma committed May 15, 2021
1 parent 3b1890b commit bbced1d
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions dateparser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
[crate-badge]: https://img.shields.io/crates/v/dateparser.svg
[crate-url]: https://crates.io/crates/dateparser

A rust library for parsing date strings in commonly used formats.
A rust library for parsing date strings in commonly used formats. Parsed date will be returned as `chrono`'s
`DateTime<Utc>`.

## Example
## Examples

Add to your `Cargo.toml`:

Expand All @@ -30,7 +31,7 @@ use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
let parsed = parse("6:15pm")?;
println("{:#?}", parsed);
println!("{:#?}", parsed);
Ok(())
}
```
Expand All @@ -39,10 +40,31 @@ Or use `str`'s `parse` method:

```rust
use dateparser::DateTimeUtc;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
let parsed = "2021-05-14 18:51 PDT".parse::<DateTimeUtc>()?.0;
println!("{:#?}", parsed);
Ok(())
}
```

Convert returned `DateTime<Utc>` to pacific time zone datetime with `chrono-tz`:

```toml
[dependencies]
chrono-tz = "0.5.3"
dateparser = "0.1.0"
```

```rust
use chrono_tz::US::Pacific;
use dateparser::DateTimeUtc;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
let parsed = "2021-05-14 18:51 PDT".parse::<DateTimeUtc>()?.0;
println("{:#?}", parsed);
println!("{:#?}", parsed.with_timezone(&Pacific));
Ok(())
}
```
Expand Down

0 comments on commit bbced1d

Please sign in to comment.