Comments (5)
What feature flags do you have enabled?
from time.
I use: serde
and serde-well-known
from time.
That can't be the case, as time::serde::format_description
is enabled by the macros
feature. Also note that the serde-well-known
flag is deliberately undocumented, as it is deprecated in favor of using the documented flags directly (namely serde
, formatting
, and parsing
).
Have you looked at the documentation for this macro? The final example shows how to use it with ISO 8601.
from time.
Ok, here is my test case.
Cargo.toml
:
[dependencies]
serde = { version = "1.0.198", features = ["derive"] }
time = { version = "0.3.36", features = ["formatting", "macros", "parsing", "serde"] }
[dev-dependencies]
serde_json = { version = "1.0.116" }
lib.rs
:
use time::{
format_description::well_known::{iso8601, Iso8601},
serde::format_description,
OffsetDateTime,
};
const CONFIG: iso8601::EncodedConfig = iso8601::Config::DEFAULT
.set_formatted_components(iso8601::FormattedComponents::DateTime)
.encode();
const FORMAT: Iso8601<CONFIG> = Iso8601::<CONFIG>;
format_description!(serde_datetime, OffsetDateTime, FORMAT);
#[derive(serde::Deserialize, Debug, PartialEq)]
pub struct Container {
#[serde(with="serde_datetime")]
pub datetime: OffsetDateTime,
}
- test:
use time::{
Date,
Month,
OffsetDateTime,
Time,
};
#[test]
fn without_offset() {
let json = serde_json::json!({
"datetime": "2024-04-17T12:45:00.0"
});
let actual: Container = serde_json::from_value(json).unwrap();
assert_eq!(
actual,
Container {
datetime: OffsetDateTime::new_utc(
Date::from_calendar_date(2024, Month::April, 17).unwrap(),
Time::from_hms(12, 45, 0).unwrap(),
),
},
);
}
Then, I got:
---- tests::without_offset stdout ----
thread 'tests::without_offset' panicked at 'called `Result::unwrap()` on an `Err` value: Error("the `Parsed` struct did not include enough information to construct the type", line: 0, column: 0)', src/lib.rs:36:62
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Worth to mention that error isn't very explicit :/
from time.
The failure is as expected, as there is no UtcOffset
present in the formatted string. As such, an OffsetDateTime
cannot be constructed.
I will look into what can be done in terms of an error message, but I suspect there isn't much.
from time.
Related Issues (20)
- `subsec_{milli,micro,nano}seconds` may have over-inclusive documented ranges HOT 1
- Default `impl Deserialize`/`impl Serialize for time::OffsetDateTime` is a footgun HOT 1
- Mark the date_time function from OffsetDateTime as public HOT 1
- Bug with leap second parsing ISO 8601 HOT 6
- Renaming of `FormatItem` is a breaking change HOT 5
- Confusing deprecation message for `time::Instant` HOT 3
- Formatting bug on ISO8601 HOT 6
- Make `format` methods localizable HOT 6
- Error with rust-nightly: type annotations needed for `Box<_>` HOT 7
- Solve "large-dates" ambiguity HOT 9
- parsing: option to [end] to terminate parsing even if there is further input HOT 1
- compile error: time-0.3.29/src/format_description/parse/mod.rs:83:9 "type must be known at this point" HOT 2
- Document status of local-offset support HOT 2
- Provide cached local offset HOT 6
- Ferrocene compiler needs more information about the type of Box<_> at compile time. HOT 1
- Serialization data corruption with Duration and `serde_human_readable` for negative subsecond durations HOT 1
- error[E0282]: type annotations needed for `Box<_>` HOT 4
- Build failure under 1.80.0 HOT 1
- Add what features should be enabled in docs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from time.