-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Return timestamps as datetime objects #14
Comments
Hi, I like this idea, however, it's a pretty significant breaking change so I don't think we'd be willing to do that for PRAW / asyncpraw. However, https://github.com/praw-dev/prawdditions might be a great place to add that conversion. |
Should I move this issue there then? |
I just moved it :) |
I feel that the best idea would be to just add a property. @property
def created_at(self):
return ...
@created_at.setter
def created_at(self, val):
self.created_utc = # Conversion code
@property
def edited_at(self):
# The same thing |
I mean, it should be as simple as: from datetime import datetime, timezone
@property
def created_at(self):
return datetime.fromtimestamp(self.created_utc, timezone.utc)
@property
def edited_at(self):
if self.edited:
return datetime.fromtimestamp(self.edited, timezone.utc)
# self.edited was False here
return self.edited # I guess? I don't think setters are needed here, since the user isn't supposed to set these attributes anyway. |
@DevilXD that's a fine approach. Would you like to make a PR? |
I'm really not familiar with how these "additions" work, nor how they hook up into the praw/asyncpraw. I don't even know where there are supposed to go. I'm okay with you just taking this code and putting it where it needs to be - unless you'll tell me when it's supposed to go, then I can do it myself. |
Hi 👋
Describe the solution you'd like
I think
Submission.created_utc
should contain adatetime
object, instead of just the unix timestamp.Describe alternatives you've considered
Currently, one has to wrap those themselves:
Now, I have two variables,
post
andposted_at
, that have information tied together, instead of just having onepost
variable, and accessing everything I'd need from it. Doing this:... is risky, because the library may not expect this data type to be there.
Additional context
This would have to be applied to every object with a
created_utc
attribute, including submissions, comments, redditors, live threads, messages, etc. The same should probably apply to theedited
attribute, which appears to be eitherfalse
or specify the edition timestamp: https://i.imgur.com/1Mwbi9X.png In this case, the attribute should probably be eitherNone
when not edited, anddatetime
specifying the edition time when edited. The current documentation of "Whether or not the submission has been edited." is slightly misleading on this fact right now.The text was updated successfully, but these errors were encountered: