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

setting Default Time that the Assignment is Due leads to an error #2572

Closed
Alex-Jordan opened this issue Sep 18, 2024 · 2 comments
Closed

setting Default Time that the Assignment is Due leads to an error #2572

Alex-Jordan opened this issue Sep 18, 2024 · 2 comments

Comments

@Alex-Jordan
Copy link
Contributor

Alex-Jordan commented Sep 18, 2024

In a course, go to Course Config, and set Default Time that the Assignment is Due to '12:30pm', and save. Then try to create a new set, either in the Sets Manager or Library Browser. This leads to an error:

Validation failed for type named Hour declared in package DateTime::Types (/usr/lib/x86_64-linux-gnu/perl5/5.34/DateTime/Types.pm) at line 101 in sub named (eval) with value 24

It sounds like something is converting the 12 (pm) to 24, and I'm guessing it should be 12 instead. And I'm not sure if 12 (am) is handled right, but that should be examined as well.

@somiaj
Copy link
Contributor

somiaj commented Sep 18, 2024

I can confirm the issue here and the following fixes it for me.

diff --git a/lib/WeBWorK/Utils/DateTime.pm b/lib/WeBWorK/Utils/DateTime.pm
index f1e13977f..3b055f917 100644
--- a/lib/WeBWorK/Utils/DateTime.pm
+++ b/lib/WeBWorK/Utils/DateTime.pm
@@ -59,7 +59,7 @@ sub getDefaultSetDueDate ($ce) {
        my ($hour, $minute, $ampm) = $ce->{pg}{timeAssignDue} =~ m/\s*(\d+)\s*:\s*(\d+)\s*(am|pm|AM|PM)?\s*/;
        $hour   //= 0;
        $minute //= 0;
-       $hour += 12 if $ampm && $ampm =~ m/pm|PM/;
+       $hour += 12 if $ampm && $ampm =~ m/pm|PM/ && $hour != 12;
+       $hour = 0 if $ampm && $ampm =~ m/am|AM/ && $hour == 12;

        my $dt = DateTime->from_epoch(epoch => time + 2 * 60 * 60 * 24 * 7);

somiaj added a commit to somiaj/webwork2 that referenced this issue Sep 18, 2024
The logic to convert to 24 hour time didn't consider 12am and 12pm
correctly, this fixes that.

This fixes issue openwebwork#2572
somiaj added a commit to somiaj/webwork2 that referenced this issue Sep 18, 2024
The logic to convert to 24 hour time didn't consider 12am and 12pm
correctly, this fixes that.

This fixes issue openwebwork#2572
somiaj added a commit to somiaj/webwork2 that referenced this issue Sep 19, 2024
The logic to convert to 24 hour time didn't consider 12am and 12pm
correctly, this fixes that.

This fixes issue openwebwork#2572
somiaj added a commit to somiaj/webwork2 that referenced this issue Sep 19, 2024
The logic to convert to 24 hour time didn't consider 12am and 12pm
correctly, this fixes that.

This fixes issue openwebwork#2572
@pstaabp
Copy link
Member

pstaabp commented Oct 1, 2024

Fixed in #2573 and #2576

@pstaabp pstaabp closed this as completed Oct 1, 2024
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