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

strptime() should assume the current year if no year is specified #48

Open
scottchiefbaker opened this issue May 11, 2020 · 5 comments
Open

Comments

@scottchiefbaker
Copy link

When using strptime() to process a string if the string does not contain a year, 1970 is assumed. It makes more sense to assume the current year. Anyone parsing a date string without a year will most likely be pulling from current years logs.

Here is a quick test case that exhibits this behavior.

use Time::Piece;

my $input = "Mar 13 14:54:27";
my $t     = localtime->strptime($input, "%b %e %T");
my $ut    = $t->epoch;
my $year  = $t->year;

print "'$input' maps to $ut / $year\n";

Outputs: 'Mar 13 14:54:27' maps to 6216867 / 1970

@smith153
Copy link
Collaborator

That's not a bad idea. 1970 was only added because originally it was left null if there was no year....and it really blew up then!

@scottchiefbaker
Copy link
Author

In my code I just manually append the current year and add " %Y" on the end of the format. It's a hack, but it works.

It would be best if Time::Piece did it natively.

@scottchiefbaker
Copy link
Author

Any updates on this?

@smith153
Copy link
Collaborator

smith153 commented Jul 2, 2020

Not at the moment but it will be in the next release.

@scottchiefbaker
Copy link
Author

Just doing a quick ping on this to see if there is anything I can do to help it along.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants