Comments (4)
I have implemented more associated constants for Iso8601
. You can view them here. As part of the change, I made it very easy to add additional configurations if there is the desire to do so in the future.
With regard to RFC 2822 and RFC 3339, I see no indication in either that there is intent to permit date-only formatting, among others. In neither RFC does the ABNF clearly show that each item is to be permitted on its own. Such an interpretation would be seem to also permit formatting only the hours, for example, which is presumably not the goal. I also checked the ABNF specification to see if there was anything implicit that I wasn't aware of, but did not find anything.
For the date
command, that's its own program that can do whatever it wants. I'm following the specifications as strictly as possible, and I don't see anything that shows it was supposed to be allowed. On the contrary, the examples only include date-time-offset values.
Ultimately, being a subset of ISO 8601
RFC 3339 may have been a subset of ISO 8601 when it was written, but it's not a subset of the latest version of ISO 8601 (from 2019). There are minor differences here and there.
As I've implemented the associated constants for ISO 8601 and don't see where it's permitted in the two RFCs, I'm closing this as completed. Thank you for the request!
from time.
For RFC 2822 and RFC 3339, the only supported formats are all-inclusive, as there is no indication in the specifications that anything else is permitted.
For ISO 8601, this can absolutely be done with the addition of an associated const.
const ISO8601_DATE: u128 = iso8601::Config::DEFAULT.set_formatted_components(FormattedComponents::Date).encode(); today.format(&Iso8601::<ISO8601_DATE>);
Completely unrelated, but do not rely on encode
returning a u128. The return type is not guaranteed. You should use the EncodedConfig
type alias.
And this has to have the config declared as a const and can't be written as a one-liner.
The config can be inlined; a separately declared const isn't strictly necessary.
- Existing formats could support formatting a date by omitting the time parts when none of them are present. (preferred)
The implementation has no knowledge of what type is actually being formatted. The default configuration for ISO 8601 is documented as formatting the date, time, and UTC offset.
- A config of Iso8601 could be provided out of the box (alongside Iso8601::DEFAULT) which does the same and doesn't require me to dig so deep into the weeds here?
This is almost certainly what will be done. It'll be quite easy to add further associated constants.
from time.
Agreed, for 2822 it probably doesn't make sense, you never see those with the time omitted either.
However I don't read RFC 3339 as requiring there be a time, and I do see date-only RFC-3339 in use. For example, GNU Coreutils' date lets you do date --rfc-3339=date
in addition to date --rfc-3339=second
which prints date and time.
The RFC's ABNF breaks it out separately as
full-date = date-fullyear "-" date-month "-" date-mday
But it doesn't positively say the time is optional either, and the examples all have both date and time.
Ultimately, being a subset of ISO 8601, as long as that code can do it easily, it doesn't matter :)
An associated const on Iso8601
would be perfect and much appreciated.
The config can be inlined; a separately declared const isn't strictly necessary.
You're right, I was getting a syntax error when I tried earlier, but I took another look and figured out what I was doing wrong. The syntax for it is very unusual (I don't think I've seen it before in my ~7 years of doing rust 😄). You have to use braces around the const expression:
today.format(&Iso8601::<{iso8601::Config::DEFAULT.set_formatted_components(FormattedComponents::Date).encode()}>)
from time.
This is great, thanks!
from time.
Related Issues (20)
- UNIX thread safety check exemptions may not be sound HOT 9
- incorrect serde version dependency requirement in Cargo.toml HOT 1
- Cargo error: `serde` conflict with `time v0.3.26` crate HOT 4
- Relax back `serde` dependency HOT 17
- The log CAN NOT display the time correctly in the LINUX with tracing_subscriber::fmt().with_timer(LocalTime::rfc_3339()) HOT 2
- error[E0557]: feature has been removed HOT 10
- errored when execute in `cargo llvm-cov` HOT 1
- Arithmetic overflow occurs HOT 4
- Missing panic condition on API docs HOT 4
- Release with coverage fix HOT 1
- Arithmetic crash occurs HOT 1
- `Weekday` and `Time` (and probably more types) do not respect formatting flags HOT 2
- Panic when `nth_next_occurrence` and `nth_prev_occurrence` get `n = 0` HOT 2
- no localtime on openbsd HOT 7
- Support providing default values during parsing HOT 1
- Sub-millisecond component inaccuracy in OffsetDateTime conversion from js_sys::Date HOT 1
- Can i try to implement `Time::parse` equivalents? HOT 1
- Unexpected behavior of `time::serde::rfc3339::option::deserialize()` HOT 3
- OffsetDateTime lacks an obvious constructor
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.