Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Time::Piece: mention how to deal with fractional seconds #18261

Closed
jidanni opened this issue Oct 21, 2020 · 3 comments
Closed

[doc] Time::Piece: mention how to deal with fractional seconds #18261

jidanni opened this issue Oct 21, 2020 · 3 comments

Comments

@jidanni
Copy link
Member

jidanni commented Oct 21, 2020

Many users will be scratching their heads about how to get e.g., 0.5 seconds parsed by Time::Piece.

Time::Piece says

Date Parsing
Time::Piece has a built-in strptime() function (from FreeBSD), allowing you incredibly flexible date
parsing routines. For example:

    my $t = Time::Piece->strptime("Sunday 3rd Nov, 1943",
                                  "%A %drd %b, %Y");

OK, but add an example of how to deal with decimal seconds: e.g., "2001-11-12T18:31:01.123Z"
Maybe the only way is

sub p {
    my $s = $_[0];
    $s=~s/(\.\d*)//;
    return Time::Piece->strptime( $s, "%Y-%m-%dT%H:%M:%SZ" ) + $1;
}

Say if that is cool or not cool. Say something, anything.
Say if one should turn to Time::HiRes here, or indeed CPAN packages.
Say if forcibly adding non integer seconds as I have above, while indeed working,
might build up residues due to float arithmetic.
Say that although in C struct tm only has intergers, but perl's Time::tm is not as strict, etc.

@Grinnz
Copy link
Contributor

Grinnz commented Oct 21, 2020

Time::Piece is maintained upstream on CPAN; its issue tracker can be found at https://rt.cpan.org/Public/Dist/Display.html?Name=Time-Piece.

@jidanni
Copy link
Member Author

jidanni commented Oct 23, 2020

Very hard to tell that here on Debian.

$ man time::piece|tail -n 1
perl v5.30.3

OK, I made https://rt.cpan.org/Ticket/Display.html?id=133599

@jkeenan
Copy link
Contributor

jkeenan commented Nov 5, 2020

Very hard to tell that here on Debian.

$ man time::piece|tail -n 1
perl v5.30.3

OK, I made https://rt.cpan.org/Ticket/Display.html?id=133599

Issue has been sent to upstream bug-tracker. Closing here.

Thank you very much.
Jim Keenan

@jkeenan jkeenan closed this as completed Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants