You are here

class PARSEMONTH in Bibliography Module 6

Same name and namespace in other branches
  1. 5 bibtexParse/PARSEMONTH.php \PARSEMONTH
  2. 6.2 modules/bibtexParse/PARSEMONTH.php \PARSEMONTH
  3. 7.3 plugins/biblio_style/bibtex/PARSEMONTH.php \PARSEMONTH
  4. 7 modules/bibtexParse/PARSEMONTH.php \PARSEMONTH
  5. 7.2 modules/bibtexParse/PARSEMONTH.php \PARSEMONTH

Hierarchy

Expanded class hierarchy of PARSEMONTH

File

bibtexParse/PARSEMONTH.php, line 26

View source
class PARSEMONTH {

  // Constructor
  function PARSEMONTH() {
  }
  function init($monthField) {
    $startMonth = $this->startDay = $endMonth = $this->endDay = FALSE;
    $date = split("#", $monthField);
    foreach ($date as $field) {
      $field = ucfirst(strtolower(trim($field)));
      if ($month = array_search($field, $this
        ->monthToLongName())) {
        if (!$startMonth) {
          $startMonth = $month;
        }
        else {
          $endMonth = $month;
        }
        continue;
      }
      else {
        if ($month = array_search($field, $this
          ->monthToShortName())) {
          if (!$startMonth) {
            $startMonth = $month;
          }
          else {
            $endMonth = $month;
          }
          continue;
        }
      }
      $this
        ->parseDay($field);
    }
    if ($this->endDay && !$endMonth) {
      $endMonth = $startMonth;
    }
    return array(
      $startMonth,
      $this->startDay,
      $endMonth,
      $this->endDay,
    );
  }

  // extract day of month from field
  function parseDay($dayField) {
    preg_match("/([0-9]+).*([0-9]+)|([0-9]+)/", $dayField, $array);
    if (array_key_exists(3, $array)) {
      if (!$this->startDay) {
        $this->startDay = $array[3];
      }
      else {
        if (!$this->endDay) {
          $this->endDay = $array[3];
        }
      }
    }
    else {
      if (array_key_exists(1, $array)) {
        $this->startDay = $array[1];
      }
      if (array_key_exists(2, $array)) {
        $this->endDay = $array[2];
      }
    }
  }

  // Convert month to long name
  function monthToLongName() {
    return array(
      1 => 'January',
      2 => 'February',
      3 => 'March',
      4 => 'April',
      5 => 'May',
      6 => 'June',
      7 => 'July',
      8 => 'August',
      9 => 'September',
      10 => 'October',
      11 => 'November',
      12 => 'December',
    );
  }

  // Convert month to short name
  function monthToShortName() {
    return array(
      1 => 'Jan',
      2 => 'Feb',
      3 => 'Mar',
      4 => 'Apr',
      5 => 'May',
      6 => 'Jun',
      7 => 'Jul',
      8 => 'Aug',
      9 => 'Sep',
      10 => 'Oct',
      11 => 'Nov',
      12 => 'Dec',
    );
  }

}

Members