mirror of
https://github.com/bspeice/dtparse
synced 2025-07-03 06:45:01 -04:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef3ea38834 | |||
741afa3451 | |||
4d7c5dd995 | |||
afb7747cdf | |||
22e0300275 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ Cargo.lock
|
|||||||
.vscode
|
.vscode
|
||||||
*.pyc
|
*.pyc
|
||||||
.idea/
|
.idea/
|
||||||
|
*.swp
|
||||||
|
@ -5,6 +5,8 @@ dist: trusty
|
|||||||
language: rust
|
language: rust
|
||||||
services: docker
|
services: docker
|
||||||
sudo: required
|
sudo: required
|
||||||
|
addons:
|
||||||
|
chrome: stable
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
@ -90,6 +92,10 @@ matrix:
|
|||||||
- env: TARGET=x86_64-unknown-linux-gnu
|
- env: TARGET=x86_64-unknown-linux-gnu
|
||||||
rust: 1.27.0
|
rust: 1.27.0
|
||||||
|
|
||||||
|
# WASM support
|
||||||
|
- env: TARGET=asmjs-unknown-emscripten USE_CARGO_WEB=true
|
||||||
|
rust: nightly
|
||||||
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- set -e
|
- set -e
|
||||||
|
16
CHANGELOG.md
16
CHANGELOG.md
@ -1,3 +1,19 @@
|
|||||||
|
Version 1.0.3 (2018-09-18)
|
||||||
|
==========================
|
||||||
|
|
||||||
|
Misc
|
||||||
|
----
|
||||||
|
|
||||||
|
- Changed the default `parse` function to use a static parser
|
||||||
|
|
||||||
|
Version 1.0.2 (2018-08-14)
|
||||||
|
==========================
|
||||||
|
|
||||||
|
Misc
|
||||||
|
----
|
||||||
|
|
||||||
|
- Add tests for WASM
|
||||||
|
|
||||||
Version 1.0.1 (2018-08-11)
|
Version 1.0.1 (2018-08-11)
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dtparse"
|
name = "dtparse"
|
||||||
version = "1.0.1"
|
version = "1.0.3"
|
||||||
authors = ["Bradlee Speice <bradlee@speice.io>"]
|
authors = ["Bradlee Speice <bradlee@speice.io>"]
|
||||||
description = "A dateutil-compatible timestamp parser for Rust"
|
description = "A dateutil-compatible timestamp parser for Rust"
|
||||||
repository = "https://github.com/bspeice/dtparse.git"
|
repository = "https://github.com/bspeice/dtparse.git"
|
||||||
@ -20,4 +20,4 @@ name = "dtparse"
|
|||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
lazy_static = "1.1"
|
lazy_static = "1.1"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
rust_decimal = "0.10"
|
rust_decimal = "^0.10.1"
|
||||||
|
@ -68,7 +68,7 @@ Further examples can be found in the [examples](examples) directory on internati
|
|||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
`dtparse` requires a minimum Rust version of 1.21 to build, but is tested on Windows, OSX,
|
`dtparse` requires a minimum Rust version of 1.21 to build, but is tested on Windows, OSX,
|
||||||
BSD, and Linux. The build is also compiled against the iOS and Android SDK's, but is not
|
BSD, Linux, and WASM. The build is also compiled against the iOS and Android SDK's, but is not
|
||||||
tested against them.
|
tested against them.
|
||||||
|
|
||||||
[dateutil]: https://github.com/dateutil/dateutil
|
[dateutil]: https://github.com/dateutil/dateutil
|
||||||
|
5
build_pycompat.py
Normal file → Executable file
5
build_pycompat.py
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
from dateutil.tz import tzutc
|
from dateutil.tz import tzutc
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -232,7 +233,7 @@ fn parse_and_assert(
|
|||||||
tzinfos: &HashMap<String, i32>,
|
tzinfos: &HashMap<String, i32>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
let mut parser = Parser::new(info);
|
let parser = Parser::new(info);
|
||||||
let rs_parsed = parser.parse(
|
let rs_parsed = parser.parse(
|
||||||
s,
|
s,
|
||||||
dayfirst,
|
dayfirst,
|
||||||
@ -282,7 +283,7 @@ fn parse_fuzzy_and_assert(
|
|||||||
tzinfos: &HashMap<String, i32>,
|
tzinfos: &HashMap<String, i32>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
let mut parser = Parser::new(info);
|
let parser = Parser::new(info);
|
||||||
let rs_parsed = parser.parse(
|
let rs_parsed = parser.parse(
|
||||||
s,
|
s,
|
||||||
dayfirst,
|
dayfirst,
|
||||||
|
1
build_pycompat_tokenizer.py
Normal file → Executable file
1
build_pycompat_tokenizer.py
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
from dateutil.parser import _timelex
|
from dateutil.parser import _timelex
|
||||||
|
|
||||||
from build_pycompat import tests
|
from build_pycompat import tests
|
||||||
|
20
ci/script.sh
20
ci/script.sh
@ -14,7 +14,27 @@ main() {
|
|||||||
cross test --target $TARGET --release
|
cross test --target $TARGET --release
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main_web() {
|
||||||
|
CARGO_WEB_RELEASE="$(curl -L -s -H 'Accept: application/json' https://github.com/koute/cargo-web/releases/latest)"
|
||||||
|
CARGO_WEB_VERSION="$(echo $CARGO_WEB_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')"
|
||||||
|
CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/$CARGO_WEB_VERSION/cargo-web-x86_64-unknown-linux-gnu.gz"
|
||||||
|
|
||||||
|
echo "Downloading cargo-web from: $CARGO_WEB_URL"
|
||||||
|
curl -L "$CARGO_WEB_URL" | gzip -d > cargo-web
|
||||||
|
chmod +x cargo-web
|
||||||
|
|
||||||
|
mkdir -p ~/.cargo/bin
|
||||||
|
mv cargo-web ~/.cargo/bin
|
||||||
|
|
||||||
|
cargo web build --target $TARGET
|
||||||
|
cargo web test --target $TARGET --release
|
||||||
|
}
|
||||||
|
|
||||||
# we don't run the "test phase" when doing deploys
|
# we don't run the "test phase" when doing deploys
|
||||||
if [ -z $TRAVIS_TAG ]; then
|
if [ -z $TRAVIS_TAG ]; then
|
||||||
|
if [ -z "$USE_CARGO_WEB" ]; then
|
||||||
main
|
main
|
||||||
|
else
|
||||||
|
main_web
|
||||||
|
fi
|
||||||
fi
|
fi
|
14
src/lib.rs
14
src/lib.rs
@ -61,6 +61,12 @@
|
|||||||
//!
|
//!
|
||||||
//! Further examples can be found in the `examples` directory on international usage.
|
//! Further examples can be found in the `examples` directory on international usage.
|
||||||
//!
|
//!
|
||||||
|
//! # Usage
|
||||||
|
//!
|
||||||
|
//! `dtparse` requires a minimum Rust version of 1.21 to build, but is tested on Windows, OSX,
|
||||||
|
//! BSD, Linux, and WASM. The build is also compiled against the iOS and Android SDK's, but is not
|
||||||
|
//! tested against them.
|
||||||
|
//!
|
||||||
//! [dateutil]: https://github.com/dateutil/dateutil
|
//! [dateutil]: https://github.com/dateutil/dateutil
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -102,6 +108,7 @@ lazy_static! {
|
|||||||
static ref ONE: Decimal = Decimal::new(1, 0);
|
static ref ONE: Decimal = Decimal::new(1, 0);
|
||||||
static ref TWENTY_FOUR: Decimal = Decimal::new(24, 0);
|
static ref TWENTY_FOUR: Decimal = Decimal::new(24, 0);
|
||||||
static ref SIXTY: Decimal = Decimal::new(60, 0);
|
static ref SIXTY: Decimal = Decimal::new(60, 0);
|
||||||
|
static ref DEFAULT_PARSER: Parser = Parser::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DecimalError> for ParseError {
|
impl From<DecimalError> for ParseError {
|
||||||
@ -664,7 +671,7 @@ impl Parser {
|
|||||||
/// order to be resolved.
|
/// order to be resolved.
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] // Need to release a 2.0 for changing public API
|
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] // Need to release a 2.0 for changing public API
|
||||||
pub fn parse(
|
pub fn parse(
|
||||||
&mut self,
|
&self,
|
||||||
timestr: &str,
|
timestr: &str,
|
||||||
dayfirst: Option<bool>,
|
dayfirst: Option<bool>,
|
||||||
yearfirst: Option<bool>,
|
yearfirst: Option<bool>,
|
||||||
@ -693,7 +700,7 @@ impl Parser {
|
|||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // Imitating Python API is priority
|
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] // Imitating Python API is priority
|
||||||
fn parse_with_tokens(
|
fn parse_with_tokens(
|
||||||
&mut self,
|
&self,
|
||||||
timestr: &str,
|
timestr: &str,
|
||||||
dayfirst: Option<bool>,
|
dayfirst: Option<bool>,
|
||||||
yearfirst: Option<bool>,
|
yearfirst: Option<bool>,
|
||||||
@ -947,7 +954,6 @@ impl Parser {
|
|||||||
) -> ParseResult<Option<FixedOffset>> {
|
) -> ParseResult<Option<FixedOffset>> {
|
||||||
// TODO: Actual timezone support
|
// TODO: Actual timezone support
|
||||||
if let Some(offset) = res.tzoffset {
|
if let Some(offset) = res.tzoffset {
|
||||||
println!("offset={}", offset);
|
|
||||||
Ok(Some(FixedOffset::east(offset)))
|
Ok(Some(FixedOffset::east(offset)))
|
||||||
} else if res.tzoffset == None
|
} else if res.tzoffset == None
|
||||||
&& (res.tzname == Some(" ".to_owned()) || res.tzname == Some(".".to_owned())
|
&& (res.tzname == Some(" ".to_owned()) || res.tzname == Some(".".to_owned())
|
||||||
@ -1277,7 +1283,7 @@ fn ljust(s: &str, chars: usize, replace: char) -> String {
|
|||||||
/// The default implementation assumes English values for names of months,
|
/// The default implementation assumes English values for names of months,
|
||||||
/// days of the week, etc. It is equivalent to Python's `dateutil.parser.parse()`
|
/// days of the week, etc. It is equivalent to Python's `dateutil.parser.parse()`
|
||||||
pub fn parse(timestr: &str) -> ParseResult<(NaiveDateTime, Option<FixedOffset>)> {
|
pub fn parse(timestr: &str) -> ParseResult<(NaiveDateTime, Option<FixedOffset>)> {
|
||||||
let res = Parser::default().parse(
|
let res = DEFAULT_PARSER.parse(
|
||||||
timestr,
|
timestr,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -16,7 +16,7 @@ fn test_fuzz() {
|
|||||||
// OverflowError: Python int too large to convert to C long
|
// OverflowError: Python int too large to convert to C long
|
||||||
// assert_eq!(parse("8888884444444888444444444881"), Err(ParseError::AmPmWithoutHour));
|
// assert_eq!(parse("8888884444444888444444444881"), Err(ParseError::AmPmWithoutHour));
|
||||||
let default = NaiveDate::from_ymd(2016, 6, 29).and_hms(0, 0, 0);
|
let default = NaiveDate::from_ymd(2016, 6, 29).and_hms(0, 0, 0);
|
||||||
let mut p = Parser::default();
|
let p = Parser::default();
|
||||||
let res = p.parse("\x0D\x31", None, None, false, false, Some(&default), false, &HashMap::new()).unwrap();
|
let res = p.parse("\x0D\x31", None, None, false, false, Some(&default), false, &HashMap::new()).unwrap();
|
||||||
assert_eq!(res.0, default);
|
assert_eq!(res.0, default);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ fn parse_and_assert(
|
|||||||
tzinfos: &HashMap<String, i32>,
|
tzinfos: &HashMap<String, i32>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
let mut parser = Parser::new(info);
|
let parser = Parser::new(info);
|
||||||
let rs_parsed = parser.parse(
|
let rs_parsed = parser.parse(
|
||||||
s,
|
s,
|
||||||
dayfirst,
|
dayfirst,
|
||||||
@ -89,7 +89,7 @@ fn parse_fuzzy_and_assert(
|
|||||||
tzinfos: &HashMap<String, i32>,
|
tzinfos: &HashMap<String, i32>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
let mut parser = Parser::new(info);
|
let parser = Parser::new(info);
|
||||||
let rs_parsed = parser.parse(
|
let rs_parsed = parser.parse(
|
||||||
s,
|
s,
|
||||||
dayfirst,
|
dayfirst,
|
||||||
|
Reference in New Issue
Block a user