#πŸ”’ help with timezones in python 3.6.6

78 messages Β· Page 1 of 1 (latest)

ivory abyss
#

so im working on a function for school and im struggling because i dont know what to do with the timezones cause im only given 1 timezone (the one from the takeoff argument.) but not another one. ive tried other timezones i would seemingly have access to but it doesnt work for some reason(1st is code, 2nd is error, 3rd is deff and specification)

stuck oceanBOT
#

@ivory abyss

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

weak sky
stuck oceanBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

ivory abyss
#
tz = pytz.timezone("America/New_York")
    joindate = parse(student[3])
    joindate2 = datetime.datetime(joindate.year, joindate.month, joindate.day, takeoff.hour, takeoff.minute, takeoff.second, tzinfo=tz)
    if joindate2 < takeoff:
        return PILOT_INVALID
    solodate = parse(student[4])
    if solodate < takeoff:
        return PILOT_NOVICE
    liscense = parse(student[5])
    if liscense < takeoff:
        return PILOT_STUDENT
    hourdate = parse(student[6])
    if hourdate < takeoff:
        return PILOT_CERTIFIED
    else:
        return PILOT_50_HOURS
unique remnant
ivory abyss
#

datetime.now??

#

oh, uhhhh. its not trying to use my current time.

#

it gives times in the test cases and uses those

#

but i was only given 1 timezone in takeoff and i dont know if i should just try to remove the timezone or try to graba different one

thorny heron
#

does student[3] include the timezone?

ivory abyss
#

no, its just a date ex:2015-01-14

thorny heron
#

Is the timezone elsewhere in the student list?

ivory abyss
#

no, the closest i have is a seperate json file in the project that has america/new york but that didnt work either

thorny heron
#

can you give an example of a student table?

ivory abyss
#

ID,LAST NAME,FIRST NAME,JOINED,SOLO,LICENSE,50 HOURS,INSTRUMENT,ADVANCED,MULTIENGINE
S00304,Wilson,Zachary,2015-01-07,2015-03-24,,,,,

thorny heron
#

so it loads from a csv file?

ivory abyss
#

some spots are empty if the thing simply hasnt happened yet

thorny heron
#

So you assume EST timezone?

ivory abyss
thorny heron
#

What's with joindate2?

ivory abyss
thorny heron
#

that's America/New York

ivory abyss
ivory abyss
#

cause i was trying almost everything

weak sky
#

are you forced to use an outdated legacy version of Python that was released almost 7 years ago?
the whole 3.6.x series has been end of life and end of support since ΓΆver 3 years
it might make things like modules/libraries harder do install because of bad compatibility with such old python versions and may also have a lot of bugs that has been addressed in newer versions

weak sky
jaunty wharf
lost harbor
# weak sky are you forced to use an outdated legacy version of Python that was released alm...

I wouldn't worry about the oldness of the Python here, unless there's funky new better tz support in a later Python.

@ivory abyss Personally my approach is to convert time data into a UNIX time, seconds since the epoch (1970). This is the number time.time() returns. And then convert to some local timezone only for presentation purposes.

That way when you import your data you convert knowing the source timezone, into a seconds value (no timezone at all). Possibly keep the source timezone around as a way to know how the original was presented.

weak sky
lost harbor
jaunty wharf
weak sky
lost harbor
#

Isn't this a bit fraught if the hhmmss part is close enough to a day boundary to be a different date in the "other" timezone?

weak sky
#

the only thing that could be a factor then is daylight savings time changes between dates if the takeoff time is within that hour before or after midnight on different sides of the DST change

lost harbor
#

I mean literally - the offical zone change is not a midnight thing.

weak sky
#

yeah, that is right

#

it's around 2 or 3 am

lost harbor
#

BTW, do we understand the OP's core problem. I'm not sure I do.

jaunty wharf
#

@lost harbor Why don't we convert the hhmmss to mins from the place it took off and then check it if it is greater than 3000 mins or not?

weak sky
#

but it still might be more correct to just assume all the student data to be at 00:00:00 in the same timezone as the takeoff datetime object

jaunty wharf
jaunty wharf
#

If I'm not overthinking this, do we need to consider the earth's relative spin?

lost harbor
#

Well: have we even seen an example student time string? Does parse() return a datetime with a timezone?

#

If both datetimes have timezones you can obtain their .timestamp() and just subtract one from the one (this is in seconds, easy peasy).

weak sky
#

just make a new datetime object of each date in the student fields and make hh:mm:ss 00:00:00 and then reuse the same timezone as the takeoff datetime object already contains

#

then it's easy to just compare the objects

lost harbor
#

If the CSV data do not have timezones in their strings, an assumption must be made, and that can affect the 50 hours thing because the timezone offset is unknown.

Unless we can assume the takeoff datetime's timezone may be used for. the CSV timezone strings.

#

That seems the core thing to figure out here. To me.

#

BTW, the OP's gone missing?

weak sky
#

the CSV example that was given only contains strings and all date strings is just a YYYY-MM-DD string

lost harbor
#

Oh, ok.

#

I'd assume then that they're in the takeoff timezone unless told otherwise.

lost harbor
#

But maybe we can just compare the date parts, and assume 0 1 2 days is < 50 hours. and more if greater.

jaunty wharf
#

What about 49 smtg hours?

weak sky
#

the takeoff parameter is just one datetime object that contains a timezone and the student parameter is a 10 element list of strings (the CSV data)

#

the date when a pilot has had 50 hours of flying after being certified is one of the fields in the list

jaunty wharf
#

Ok so looking at the image again, the error doesn't seem to be with 50 hours, it seems to be with licence present or not

weak sky
#

so it's just another date to compare against

#

or rather, another date string to be parsed into a datetime object and then compared with the takeoff datetime object

jaunty wharf
#

And he has given 'joindate' is less than take off which is obviously true in all cases that's why it showed invalid pilot instead of a novice I believe.

weak sky
#

not necessarily true in all cases, the test inputs can contain "students" that isn't even enrolled

#

but for most inputs should be, yes

#

but we can't just look at joindate as there are 7 different possible date fields in the input but I don't think all are needed to be checked to return the right response

jaunty wharf
#

Yeah so, where is the OP?

#

Would be great if he explained it better

weak sky
jaunty wharf
#

Yeah

weak sky
weak sky
#

@ivory abyss are you still around?

jaunty wharf
#

It was a good discussion, I got to go, bye

stuck oceanBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.