You are here

function cmfcCalendarV1Iranian::date in Calendar Systems 7.3

Same name and namespace in other branches
  1. 8 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::date()
  2. 8.2 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::date()
  3. 5 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::date()
  4. 6.3 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::date()
  5. 6 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::date()
  6. 7 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::date()
  7. 7.2 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::date()

Implementation of PHP date function This is the simplified versino by Sina Salek

3 calls to cmfcCalendarV1Iranian::date()
cmfcCalendarV1Iranian::smartGet in calendar/v1/calendarSystems/iranian.class.inc.php
@desc accept array,timestamp and string as input datetime in jalali or gregorian format
cmfcCalendarV1Iranian::timestampToInfoArray in calendar/v1/calendarSystems/iranian.class.inc.php
cmfcCalendarV1Iranian::timestampToStr in calendar/v1/calendarSystems/iranian.class.inc.php

File

calendar/v1/calendarSystems/iranian.class.inc.php, line 146

Class

cmfcCalendarV1Iranian

Code

function date($format, $maket = null) {
  $farsi = 1;
  $type = $format;

  //set 1 if you want translate number to farsi or if you don't like set 0
  $transnumber = false;

  ///chosse your timezone
  $TZhours = 0;
  $TZminute = 0;
  $need = "";
  $result1 = "";
  $result = "";
  if (is_null($maket)) {
    $year = $this
      ->phpDate("Y");
    $month = $this
      ->phpDate("m");
    $day = $this
      ->phpDate("d");
    $maket = mktime($this
      ->phpDate("H") + $TZhours, $this
      ->phpDate("i") + $TZminute, $this
      ->phpDate("s"), $this
      ->phpDate("m"), $this
      ->phpDate("d"), $this
      ->phpDate("Y"));
  }
  else {
    $maket += $TZhours * 3600 + $TZminute * 60;
    $year = $this
      ->phpDate("Y", $maket);
    $month = $this
      ->phpDate("m", $maket);
    $day = $this
      ->phpDate("d", $maket);
  }
  $need = $maket;
  $i = 0;
  $subtype = "";
  $subtypetemp = "";
  list($jyear, $jmonth, $jday) = $this
    ->fromGregorian($year, $month, $day);
  while ($i < strlen($type)) {
    $subtype = substr($type, $i, 1);
    if ($subtypetemp == "\\") {
      $result .= $subtype;
      $i++;
      continue;
    }
    switch ($subtype) {
      case "A":
        $result1 = $this
          ->phpDate("a", $need);
        $result .= $this
          ->getMeridiemName($result1);
        break;
      case "a":
        $result1 = $this
          ->phpDate("a", $need);
        $result .= $this
          ->getMeridiemShortName($result1);
      case "d":
        if ($jday < 10) {
          $result1 = "0" . $jday;
        }
        else {
          $result1 = $jday;
        }
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "D":
        $result1 = $this
          ->phpDate("w", $need);
        $result .= $this
          ->getWeekShortName($result1);
        break;
      case "F":
        $result .= $this
          ->getMonthName($jmonth);
        break;
      case "g":
        $result1 = $this
          ->phpDate("g", $need);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "G":
        $result1 = $this
          ->phpDate("G", $need);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "h":
        $result1 = $this
          ->phpDate("h", $need);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "H":
        $result1 = $this
          ->phpDate("H", $need);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "i":
        $result1 = $this
          ->phpDate("i", $need);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "j":
        $result1 = $jday;
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "l":
        $result1 = $this
          ->phpDate("w", $need);
        $result .= $this
          ->getWeekName($result1);
        break;
      case "m":
        if ($jmonth < 10) {
          $result1 = "0" . $jmonth;
        }
        else {
          $result1 = $jmonth;
        }
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "M":
        $result .= $this
          ->getMonthShortName($jmonth);
        break;
      case "n":
        $result1 = $jmonth;
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "s":
        $result1 = $this
          ->phpDate("s", $need);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "S":
        $result .= html_entity_decode("&#1575;&#1605;", ENT_QUOTES, 'UTF-8');
        break;
      case "t":
        $result .= $this
          ->monthTotalDays($month, $day, $year);
        break;
      case "w":
        $result1 = $this
          ->phpDate("w", $need);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "y":
        $result1 = substr($jyear, 2, 4);
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "Y":
        $result1 = $jyear;
        if ($transnumber == 1) {
          $result .= cmfcString::convertNumbersToFarsi($result1);
        }
        else {
          $result .= $result1;
        }
        break;
      case "U":
        $result .= $this
          ->phpTime();
        break;
      case "Z":
        $result .= $this
          ->yearTotalDays($jmonth, $jday, $jyear);
        break;
      case "L":
        list($tmp_year, $tmp_month, $tmp_day) = $this
          ->toGregorian(1384, 12, 1);

        /*
        echo $tmp_day;
        if(lastday($tmp_month,$tmp_day,$tmp_year)=="31")
            $result.="1";
        else
            $result.="0";
        */
        break;
      default:
        $result .= $subtype;
    }
    $subtypetemp = substr($type, $i, 1);
    $i++;
  }
  return $result;
}