GithubHelp home page GithubHelp logo

Comments (4)

jhpratt avatar jhpratt commented on May 27, 2024 2

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.

jhpratt avatar jhpratt commented on May 27, 2024 1

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.

wfraser avatar wfraser commented on May 27, 2024

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.

wfraser avatar wfraser commented on May 27, 2024

This is great, thanks!

from time.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.