You are here

class DatexObjectUtils in Datex 7

Utitilities to work with a DatexObject

Hierarchy

Expanded class hierarchy of DatexObjectUtils

File

datex_api/datex_api_classes.inc, line 981
API and helper functions used by other datex modules.

View source
class DatexObjectUtils {

  /**
   * Returns first day of a month.
   */
  public static function monthFirstDay($date = NULL) {
    $date = new DatexObject($date, FALSE);
    return $date
      ->monthFirstDay();
  }

  /**
   * Returns last day of a month.
   */
  public static function monthLastDay($date = NULL) {
    $date = new DatexObject($date, FALSE);
    return $date
      ->monthLastDay();
  }

  /**
   * Returns granularity parts of a given date in an array.
   */
  public static function toArray($date = NULL) {
    if (!is_a($date, 'DatexObject')) {
      $date = new DatexObject($date, FALSE);
    }
    return $date
      ->toArray();
  }

  /**
   * Returns a Jalali Object from a given date.
   */
  public static function getJalaliObject($date = NULL) {
    return new DatexObject($date, FALSE);
  }

  /**
   * Returns current Jalali Year.
   */
  public static function getYear() {
    return self::getByName('year');
  }

  /**
   * Returns current Jalali month.
   */
  public static function getMonth() {
    return self::getByName('month');
  }

  /**
   * Returns current Jalali day.
   */
  public static function getDay() {
    return self::getByName('day');
  }

  /**
   * Get current part of date as specified in name. Any of day, month, year.
   */
  public static function getByName($name) {
    $date = DatexFormatter::toJalali();
    return $date[$name];
  }

  /**
   * See php date().
   */
  public static function date($format, $timestamp = NULL) {
    return DatexFormatter::format($timestamp === NULL ? time() : $timestamp, $format);
  }

  /**
   * See php mktime().
   */
  public static function mktime($hour = NULL, $minute = NULL, $second = NULL, $month = NULL, $day = NULL, $year = NULL) {
    $date = DatexFormatter::toGregorian($year, $month, $day);
    $year = $year === NULL ? NULL : $date['year'];
    $month = $month === NULL ? NULL : $date['month'];
    $day = $day === NULL ? NULL : $date['day'];
    return mktime($hour, $minute, $second, $month, $day, $year);
  }

  /**
   * See php getdate().
   */
  public static function getdate($timestamp = NULL) {
    if ($timestamp === NULL) {
      $timestamp = time();
    }
    $date = new DateTime($timestamp);
    $ret['seconds'] = intval($date
      ->format('s'));
    $ret['minutes'] = intval($date
      ->format('i'));
    $ret['hours'] = intval($date
      ->format('G'));
    $jalali = DatexFormatter::toJalali();
    $ret['mday'] = intval($jalali['day']);
    $ret['mon'] = intval($jalali['month']);
    $ret['year'] = intval($jalali['year']);
    $ret['wday'] = DatexFormatter::formatPHP($date, 'w');
    $ret['yday'] = DatexFormatter::formatPHP($date, 'z');
    $ret['weekday'] = DatexFormatter::formatPHP($date, 'l');
    $ret['month'] = DatexFormatter::formatPHP($date, 'F');
    $ret[0] = $timestamp;
    return $ret;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DatexObjectUtils::date public static function See php date().
DatexObjectUtils::getByName public static function Get current part of date as specified in name. Any of day, month, year.
DatexObjectUtils::getdate public static function See php getdate().
DatexObjectUtils::getDay public static function Returns current Jalali day.
DatexObjectUtils::getJalaliObject public static function Returns a Jalali Object from a given date.
DatexObjectUtils::getMonth public static function Returns current Jalali month.
DatexObjectUtils::getYear public static function Returns current Jalali Year.
DatexObjectUtils::mktime public static function See php mktime().
DatexObjectUtils::monthFirstDay public static function Returns first day of a month.
DatexObjectUtils::monthLastDay public static function Returns last day of a month.
DatexObjectUtils::toArray public static function Returns granularity parts of a given date in an array.