- Support
- Forums
- SimpleQuiz
- Extension Forums
- SimpleQuiz Forum
- Something wrong with date time computation when quiz is limited to once a day
Something wrong with date time computation when quiz is limited to once a day
- John Bongiovanni
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
2 years 5 months ago #1
by John Bongiovanni
Something wrong with date time computation when quiz is limited to once a day was created by John Bongiovanni
I have a quiz setup as once day. I took the quiz around 4pm local time yesterday. When I tried to retake it today at 10am local, it told me I had already taken the quiz today. I waited until 7pm local time, thinking it might have been using 24 hours instead of next day, but it told me I had already taken the quiz today.
I suspect the computation is not handling local dates and times correctly. I can give login and specifics, if that helps.
I suspect the computation is not handling local dates and times correctly. I can give login and specifics, if that helps.
Please Log in or Create an account to join the conversation.
- Christopher Mavros
- Offline
- Administrator
2 years 5 months ago #2
by Christopher Mavros
Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!
Replied by Christopher Mavros on topic Something wrong with date time computation when quiz is limited to once a day
Hello John and thank you for posting.
This can happen.
At the moment, the calculation method retrieves the last result date from the database and compares it with the current database time to extract the number of days from the last play.
Please check your Website Time Zone in the Global Configuration server tab. This may have just been a mix-up.
If your timezone is correctly configured and the server timezone and database timezone is also the same, then let me know and I will look into it a little bit further.
Thanks again.
This can happen.
At the moment, the calculation method retrieves the last result date from the database and compares it with the current database time to extract the number of days from the last play.
Please check your Website Time Zone in the Global Configuration server tab. This may have just been a mix-up.
If your timezone is correctly configured and the server timezone and database timezone is also the same, then let me know and I will look into it a little bit further.
Thanks again.
Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!
Please Log in or Create an account to join the conversation.
- John Bongiovanni
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
2 years 5 months ago #3
by John Bongiovanni
Replied by John Bongiovanni on topic Something wrong with date time computation when quiz is limited to once a day
That explains it. The server time zone is UTC and the database time zone is America/Chicago, two hours ahead of America/Los_Angeles, which is the website time zone. I think I can change the database time zone. Will that fix it?
Also, it sounds like once per day really means wait 24 hours before taking it again. Correct? That's fine, but the error message should say that, as "you have already taken the quiz today" would be interpreted as this calendar day.
Also, it sounds like once per day really means wait 24 hours before taking it again. Correct? That's fine, but the error message should say that, as "you have already taken the quiz today" would be interpreted as this calendar day.
Please Log in or Create an account to join the conversation.
- Christopher Mavros
- Offline
- Administrator
2 years 5 months ago #4
by Christopher Mavros
Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!
Replied by Christopher Mavros on topic Something wrong with date time computation when quiz is limited to once a day
Yes, this should probably fix it.
The way it works now, it calculates the date difference between today and the last saved result, so it should work with calendar days and not 24-hour spans.
Let me know if you need any further help.
The way it works now, it calculates the date difference between today and the last saved result, so it should work with calendar days and not 24-hour spans.
Let me know if you need any further help.
Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!
Please Log in or Create an account to join the conversation.
- John Bongiovanni
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 25
- Thank you received: 0
2 years 5 months ago #5
by John Bongiovanni
Replied by John Bongiovanni on topic Something wrong with date time computation when quiz is limited to once a day
Unfortunately, with my plan on my hosting service (shared server on SiteGround), I can change neither the server time nor the database time.
I know dealing with datetime is really painful, and I'm clearly not familiar with your implementation, so the following may not make sense.
I am assuming that you are setting the datetime_taken in SQL, i.e. using NOW() or something similar, which means that the times recorded
are in database timezone. If that is indeed the case, you could do the computation based on NOW() rather than anything supplied by PHP.
If this is not something you can solve easily, I'd like to at least explain to the quiz takers how long they have to wait to take it again.
I know dealing with datetime is really painful, and I'm clearly not familiar with your implementation, so the following may not make sense.
I am assuming that you are setting the datetime_taken in SQL, i.e. using NOW() or something similar, which means that the times recorded
are in database timezone. If that is indeed the case, you could do the computation based on NOW() rather than anything supplied by PHP.
If this is not something you can solve easily, I'd like to at least explain to the quiz takers how long they have to wait to take it again.
Please Log in or Create an account to join the conversation.
- Christopher Mavros
- Offline
- Administrator
2 years 5 months ago #6
by Christopher Mavros
Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!
Replied by Christopher Mavros on topic Something wrong with date time computation when quiz is limited to once a day
Hi again John.
After taking a closer look at the code and its behavior, I made some fixes and published them about an hour ago.
Here's what the behavior is now.
Since SimpleQuiz allows administrators to disable the saving of results in the database, SimpleQuiz leaves a cookie on the user's computer to limit playing this quiz for 24 hours. This explains the initial behavior of the 24-hour limit rather than the calendar date. Now this cookie is only checked if there are no results in the database, which is applied also when the user's session has expired and they are not logged-in to the site, so their previous results cannot be matched to them.
I have changed the database check to use the server time. I know that you suggested the opposite, but the results were saved using server time (which is actually required in order to maintain the same value accross multiple inserts rather than using mysql NOW). So, both the result insertion and the result date evaluation use server time now. The comparison is made in calendar days.
Concluding: If a user is not logged-in, or saving results in the database is disabled, SimpleQuiz uses a cookie that expires after 24 hours.
Otherwise, the database results are used, limiting quiz play within 1, 7 or 30 calendar days, depending on your settings for each quiz.
Hope this helps.
Thanks again
After taking a closer look at the code and its behavior, I made some fixes and published them about an hour ago.
Here's what the behavior is now.
Since SimpleQuiz allows administrators to disable the saving of results in the database, SimpleQuiz leaves a cookie on the user's computer to limit playing this quiz for 24 hours. This explains the initial behavior of the 24-hour limit rather than the calendar date. Now this cookie is only checked if there are no results in the database, which is applied also when the user's session has expired and they are not logged-in to the site, so their previous results cannot be matched to them.
I have changed the database check to use the server time. I know that you suggested the opposite, but the results were saved using server time (which is actually required in order to maintain the same value accross multiple inserts rather than using mysql NOW). So, both the result insertion and the result date evaluation use server time now. The comparison is made in calendar days.
Concluding: If a user is not logged-in, or saving results in the database is disabled, SimpleQuiz uses a cookie that expires after 24 hours.
Otherwise, the database results are used, limiting quiz play within 1, 7 or 30 calendar days, depending on your settings for each quiz.
Hope this helps.
Thanks again
Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!
Please Log in or Create an account to join the conversation.
Moderators: Christopher Mavros
- Home
- Support
- Forums
- SimpleQuiz
- Extension Forums
- SimpleQuiz Forum
- Something wrong with date time computation when quiz is limited to once a day