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)
- fn OffsetDateTime::date_time(self) if private HOT 1
- Optional weekday for rfc2822 HOT 2
- year repr:last_two removed in 0.3.x? HOT 1
- Optional leading zeros and parsing HOT 3
- Implement `FromStr` for `PrimitiveDateTime` and `OffsetDateTime` HOT 1
- `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
- How to use `serde::format_description` with `format_description::well_known` ? 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
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.