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)
#π help with timezones in python 3.6.6
78 messages Β· Page 1 of 1 (latest)
@ivory abyss
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.
Closes after a period of inactivity, or when you send !close.
!code -post the code as text like described below using backticks
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
can u not just datetime.now() - given datetime and go from there ?
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
does student[3] include the timezone?
no, its just a date ex:2015-01-14
Is the timezone elsewhere in the student list?
no, the closest i have is a seperate json file in the project that has america/new york but that didnt work either
can you give an example of a student table?
ID,LAST NAME,FIRST NAME,JOINED,SOLO,LICENSE,50 HOURS,INSTRUMENT,ADVANCED,MULTIENGINE
S00304,Wilson,Zachary,2015-01-07,2015-03-24,,,,,
so it loads from a csv file?
some spots are empty if the thing simply hasnt happened yet
So you assume EST timezone?
yes and no. it gives a list from the csv file, but it does come from a csv file
What's with joindate2?
so just try pytz.timezone("EST")
that's America/New York
so then ive already tried that
a rewrite of joindate, with time and timezone
cause i was trying almost everything
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
is the signature of the function in 3rd image provided by the assignment?
Is the timezone close to America/NewYork or it is America/NewYork?
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.
i neither see a time or timezone in the example input data, just a date, so i don't know how that would go together with the datetime object with a timezone that is sent in as the ftakeoff parameter to the function
The OP may need to assume the input data is localised to the takeoff datetime thing's timezone.
Hey there, I might have a very silly doubt here, then we take an input for every flight's timezone, assign it into a variable and then put the variable in place of America/NewYork?
and i agree, the unix epoch is probably a good thing to use, but it's still very strange to have to take the time and timezone into account if all there is to compare it with is dates, then one can just trancate the takeoff time to only compare the dates
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?
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
These are often sheduled for 1am/2am explicitly to avoid the date component changing at the cutover time.
I mean literally - the offical zone change is not a midnight thing.
BTW, do we understand the OP's core problem. I'm not sure I do.
@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?
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
That would make it simple for calculating and conversions right?
i think so
If I'm not overthinking this, do we need to consider the earth's relative spin?
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).
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
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?
the CSV example that was given only contains strings and all date strings is just a YYYY-MM-DD string
here is the example data
But maybe we can just compare the date parts, and assume 0 1 2 days is < 50 hours. and more if greater.
What about 49 smtg hours?
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
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
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
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.
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
haha, that's as great question π
Yeah
i think the images gives enough information, but as this is tagged as homework we should only guide OP to a solution, not give finished code
but it's hard to guide OP if they aren't around to be guided
Right.
@ivory abyss are you still around?
It was a good discussion, I got to go, bye
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.