Uploaded image for project: 'Plugins'
  1. Plugins
  2. CONTRIB-2215

A new dateformat type Spanish users (DD/MM/YYYY)

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.9
    • Fix Version/s: 1.9.10
    • Component/s: Block: Birthday
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      I added some lines to the code of block_birthday.php to deal with the most used date format in Spanish: DD/MM/YYY. The current version allow to choose from ISO (YYYY.MM.DD), USA (MM.DD.YYYY), and EUR (DD.MM.YYYY).

      I added a new date format wich I called es_EUR (DD/MM/YYYY).

      Modifications are very simple and basically consist on copy an existing 'switch - case' valid for a preexisting date format (for example EUR) and pasted again as es_EUR to work with a different format:

      Additions in block_birthday.php are:

      a.- In original file, line 7:

      --------------------- Original ----------------------------
      switch ($format)

      { case 'USA': $period = explode('.',$date); $month = $period[0]; $day = $period[1]; break; case 'ISO': $period = explode('-',$date); $month = $period[1]; $day = $period[2]; break; case 'EUR': $period = explode('.',$date); $month = $period[1]; $day = $period[0]; break; default : error('Invalid field type'); }

      -------------------End Original --------------------------

      --------------------- Changes ----------------------------
      switch ($format)

      { case 'USA': $period = explode('.',$date); $month = $period[0]; $day = $period[1]; break; case 'ISO': $period = explode('-',$date); $month = $period[1]; $day = $period[2]; break; case 'EUR': $period = explode('.',$date); $month = $period[1]; $day = $period[0]; break; case 'es_EUR': $period = explode('/',$date); $month = $period[1]; $day = $period[0]; break; default : error('Invalid field type'); }

      -------------------End Changes ----------------------------

      b.- In original file, line 90:

      --------------------- Original ----------------------------
      switch ($dateformat)

      { case 'ISO' : $sqldate = 'str_to_date(ud.data,"%Y-%m-%d")'; break; case 'EUR' : $sqldate = 'str_to_date(ud.data,"%d.%m.%Y")'; break; case 'USA' : $sqldate = 'str_to_date(ud.data,"%m.%d.%Y")'; break; default : $sqldate = 'str_to_date(ud.data,"%Y-%m-%d")'; }

      -------------------End Original --------------------------

      --------------------- Changes ----------------------------
      switch ($dateformat)

      { case 'ISO' : $sqldate = 'str_to_date(ud.data,"%Y-%m-%d")'; break; case 'EUR' : $sqldate = 'str_to_date(ud.data,"%d.%m.%Y")'; break; case 'USA' : $sqldate = 'str_to_date(ud.data,"%m.%d.%Y")'; break; case 'es_EUR' : $sqldate = 'str_to_date(ud.data,"%d\/%m\/%Y")'; break; default : $sqldate = 'str_to_date(ud.data,"%Y-%m-%d")'; }

      -------------------End Changes ----------------------------

      I'm not an expert in PHP, but I think changes don't concern security issues.

      I also added new lines in config_global.html template to allow users to choose the new date format.

      --------------------- Original ----------------------------
      <td>
      <select name="block_birthday_dateformat">

      <option value="ISO" <?php if(isset($config_birthday->block_birthday_dateformat)){
      if($config_birthday->block_birthday_dateformat == "ISO")

      { echo "selected=\"selected\"";}
      }else{ echo "selected=\"selected\""; }?>
      ><?php p(get_string('dateformatiso', 'block_birthday')) ?></option>

      <option value="USA" <?php if(isset($config_birthday->block_birthday_dateformat)){
      if($config_birthday->block_birthday_dateformat == "USA"){ echo "selected=\"selected\""; }
      }?>
      ><?php p(get_string('dateformatusa', 'block_birthday')) ?></option>

      <option value="EUR" <?php if(isset($config_birthday->block_birthday_dateformat)){
      if($config_birthday->block_birthday_dateformat == "EUR"){ echo "selected="selected""; }
      }?>
      ><?php p(get_string('dateformateur', 'block_birthday')) ?></option>

      </select>
      </td>
      --------------------- End Original ----------------------------

      --------------------- Changes ----------------------------
      <td>
      <select name="block_birthday_dateformat">

      <option value="ISO" <?php if(isset($config_birthday->block_birthday_dateformat)){
      if($config_birthday->block_birthday_dateformat == "ISO"){ echo "selected="selected"";}

      }else

      { echo "selected=\"selected\""; }

      ?>
      ><?php p(get_string('dateformatiso', 'block_birthday')) ?></option>

      <option value="USA" <?php if(isset($config_birthday->block_birthday_dateformat)){
      if($config_birthday->block_birthday_dateformat == "USA")

      { echo "selected=\"selected\""; }
      }?>
      ><?php p(get_string('dateformatusa', 'block_birthday')) ?></option>

      <option value="EUR" <?php if(isset($config_birthday->block_birthday_dateformat)){
      if($config_birthday->block_birthday_dateformat == "EUR"){ echo "selected="selected""; }

      }?>
      ><?php p(get_string('dateformateur', 'block_birthday')) ?></option>

      <option value="es_EUR" <?php if(isset($config_birthday->block_birthday_dateformat)){
      if($config_birthday->block_birthday_dateformat == "EUR")

      { echo "selected=\"selected\""; }

      }?>
      ><?php p(get_string('dateformates_eur', 'block_birthday')) ?></option>

      </select>
      </td>
      --------------------- End Changes ----------------------------

      I've also added a new string to EACH ONE of the current lang translations to support this feature. Basically it consisted in add the line:

      $string['dateformates_eur'] = 'es_EUR Date format: \'%%d/%%m/%%Y\'';

      ... to the existing ones.

      A simple copy & paste let me mdified ALL the translations because the only thing I had to replace was 'EUR' by 'es_EUR'.

      I have also made a new lang translations for 'Galician Language' that didn't exist (gl_utf8).

      Finally I added to the README.TXT a reference to the es_EUR date format added.

      I send you all the modifications in a attached zip file named birthday_modifications._2010_07_22.zip

      I read in the discussion forum of birthday block that a Brazilian users asked for a date format as the one I tried to implement.

      If you think that this customization is worth, let me know and I'll use it for my School. If not, I'll forget it.

      Best regards form Vigo (Spain)

      Toni Soto

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aborrow Anthony Borrow
              Reporter:
              tonisoto Toni Soto
              Participants:
              Component watchers:
              Anthony Borrow
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                25/Oct/10