Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-54750

Properly handle unset dates with datetime field

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.1
    • Fix Version/s: None
    • Component/s: Unknown
    • Labels:

      Description

      All over moodle we use 0 or the empty string to mean 'not set'. In a lot of cases this doesn't matter that much as long as you are careful. With timestamps however, it does matter - since 0 is a valid timestamp. At least one are this affects is user profile fields. If you add a date field to it, and save the date 1 January 1970 (with the user's timezone set to UTC) it will save the date as 0 in the database, and it will be treated as unset. We should be using null for unset dates.

      To see an example of this:

      1. Go to "Site administration" >"Location" > "Location settings"
      2. Set "Force timezone" to UTC
      3. Go to "Site administration" > "Users" > "Accounts" > "User profile fields"
      4. Select "datetime" from the drop down
      5. Set the start year to some year before 1970, leave everything else
      6. Save
      7. Edit a user's profile
      8. Set the new datetime field to 1 January 1970, save the profile
      9. Check their profile and notice that the field is not set

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                cameron1729 cameron1729
                Participants:
                Component watchers:
                Amaia Anabitarte, Bas Brands, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: