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

[ENH] Add datetime functionality to support offsets and other manipulations #699

Open
dshanske opened this issue Oct 30, 2021 · 3 comments
Assignees

Comments

@dshanske
Copy link

Is your feature request related to a problem? Please describe.

The function that retrieves a date always converts it to the timezone of the site. I want to preserve the original timezone.

Describe the solution you'd like

Suggest a new version of the get_date and other related functions that returns a datetime object. Then the existing functions can call that function and format it.

Describe alternatives you've considered

I've considered copying the function into my own code and reimplenting it, but it seems unnecessary.

@JanPetterMG
Copy link
Contributor

There's way too many DateTime formats used in feeds out there on the internet. Some use american, others european formats. If that wasn't enough, many websites create their own custom formats (for no obvious reason). Tomorrows date can be specified as both 01-11-21, 11-01-21 and 21-11-01. It really depends on what feed you're parsing.
Yes there are standards out there, but not everyone really cares, if their feed uses the right formats or not. Similarly, not all feeds are escaping special characters in the description either, making many feeds to periodically fail parsing or validations.

It also isn't uncommon for websites to specify their local time, with an +0:00 at the end, making it seem like an UTC/GMT-timestamp, even when it's not...

I would highly recommend anyone to parse the raw timestamp value on their own, depending on witch site it comes from.
$pubDate = $pie->get_date(null);

@dshanske
Copy link
Author

I was just talking about having it return a DateTime object.

@JanPetterMG
Copy link
Contributor

JanPetterMG commented Oct 31, 2021

Yeah, I know, but the DateTime object needs an input format, to be able to parse the date. If the standardized formats are wrong, for some reason, so is the the date, returned by the DateTime object.
I've seen way too many DateTime objects return just january 1st 1970 (or even false), due to some month/weekday in foreign language (or unknown format in general)

Why don't you just use something like this?

$date = new DateTime($pie->get_date(null));
// or
$date = DateTime::createFromFormat('Y-m-d', $pie->get_date(null), new DateTimeZone('UTC'));

Edit: Added second example.

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

3 participants