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

Properly handle unset dates with datetime field

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Won't Do
    • 3.1
    • None
    • Administration

    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

              Unassigned Unassigned
              cameron1729 cameron1729
              David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: