fixbug get methods

This commit is contained in:
Nasser committed 2020-03-05 19:31:37 +03:30
1 parent 2fec7f078a
commit c62f2a6c94
2 files changed
+116 -114

No files matched your search

+2 -2
View File
@@ -12,8 +12,8 @@
"require": { "require": {
"php": ">=5.5", "php": ">=5.5",
"hekmatinasser/notowo": "^1.0", "hekmatinasser/notowo": "^1.0",
"illuminate/validation": "^5|^6", "illuminate/validation": "^5|^6|^7",
"illuminate/support": "^5|^6" "illuminate/support": "^5|^6|^7"
}, },
"require-dev" : { "require-dev" : {
"phpunit/phpunit": "7.2.*", "phpunit/phpunit": "7.2.*",
+114 -112
View File
@@ -20,7 +20,7 @@ class Verta extends DateTime {
/***************************** STATCT VARIABLE ****************************/ /***************************** STATCT VARIABLE ****************************/
/** /**
* The day constants * The day constants
*/ */
const SATURDAY = 0; const SATURDAY = 0;
@@ -31,7 +31,7 @@ class Verta extends DateTime {
const THURSDAY = 5; const THURSDAY = 5;
const FRIDAY = 6; const FRIDAY = 6;
/** /**
* Number unit in date * Number unit in date
*/ */
const YEARS_PER_CENTURY = 100; const YEARS_PER_CENTURY = 100;
@@ -47,7 +47,7 @@ class Verta extends DateTime {
/** /**
* Word use in format datetime. * Word use in format datetime.
*/ */
const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s'; const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s';
/** /**
@@ -99,18 +99,18 @@ class Verta extends DateTime {
* @var array * @var array
*/ */
protected static $daysMonthGregorian = array( protected static $daysMonthGregorian = array(
31, 31,
28, 28,
31, 31,
30, 30,
31, 31,
30, 30,
31, 31,
31, 31,
30, 30,
31, 31,
30, 30,
31, 31,
); );
/** /**
@@ -118,39 +118,39 @@ class Verta extends DateTime {
* *
* @var array * @var array
*/ */
protected static $daysMonthJalali = array( protected static $daysMonthJalali = array(
31, 31,
31, 31,
31, 31,
31, 31,
31, 31,
31, 31,
30, 30,
30, 30,
30, 30,
30, 30,
30, 30,
29, 29,
); );
/** /**
* month name jalali * month name jalali
* *
* @var array * @var array
*/ */
protected static $monthYear = array( protected static $monthYear = array(
'فروردین', 'فروردین',
'اردیبهشت', 'اردیبهشت',
'خرداد', 'خرداد',
'تیر', 'تیر',
'مرداد', 'مرداد',
'شهریور', 'شهریور',
'مهر', 'مهر',
'آبان', 'آبان',
'آذر', 'آذر',
'دی', 'دی',
'بهمن', 'بهمن',
'اسفند', 'اسفند',
); );
/** /**
@@ -173,31 +173,31 @@ class Verta extends DateTime {
* *
* @var array * @var array
*/ */
protected static $unitName = array( protected static $unitName = array(
'ثانیه', 'ثانیه',
'دقیقه', 'دقیقه',
'ساعت', 'ساعت',
'روز', 'روز',
'هفته', 'هفته',
'ماه', 'ماه',
'سال', 'سال',
'قرن' 'قرن'
); );
/** /**
* unit date number. * unit date number.
* *
* @var array * @var array
*/ */
protected static $unitNumber = array( protected static $unitNumber = array(
self::SECONDS_PER_MINUTE, self::SECONDS_PER_MINUTE,
self::MINUTES_PER_HOUR, self::MINUTES_PER_HOUR,
self::HOURS_PER_DAY, self::HOURS_PER_DAY,
self::DAYS_PER_WEEK, self::DAYS_PER_WEEK,
self::WEEKS_PER_MONTH, self::WEEKS_PER_MONTH,
self::MONTHS_PER_YEAR, self::MONTHS_PER_YEAR,
self::YEARS_PER_DECADE, self::YEARS_PER_DECADE,
); );
/** /**
* persian number. * persian number.
@@ -244,7 +244,7 @@ class Verta extends DateTime {
* @param bool $timezone [optional] * @param bool $timezone [optional]
* @internal param timestamp $timestamp [optional] * @internal param timestamp $timestamp [optional]
*/ */
public function __construct($datetime = null, $timezone = null) { public function __construct($datetime = null, $timezone = null) {
if ($datetime === null) { if ($datetime === null) {
$object = new DateTime(); $object = new DateTime();
$instance = $object->getTimestamp(); $instance = $object->getTimestamp();
@@ -262,13 +262,13 @@ class Verta extends DateTime {
elseif (is_numeric($datetime)) { elseif (is_numeric($datetime)) {
$instance = $datetime; $instance = $datetime;
} }
else { else {
throw new \InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime)); throw new \InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
} }
$timezone = static::createTimeZone($timezone); $timezone = static::createTimeZone($timezone);
parent::__construct(date('Y-m-d H:i:s.u', $instance), $timezone); parent::__construct(date('Y-m-d H:i:s.u', $instance), $timezone);
} }
/** /**
* Create a Verta now datetime * Create a Verta now datetime
@@ -349,7 +349,7 @@ class Verta extends DateTime {
return new DateTime(date('Y-m-d H:i:s.u', $this->getTimestamp()), $this->getTimeZone()); return new DateTime(date('Y-m-d H:i:s.u', $this->getTimestamp()), $this->getTimeZone());
} }
/** /**
* Create a Verta instance from a DateTime one * Create a Verta instance from a DateTime one
* *
* @param timestamp $datetime [optional] * @param timestamp $datetime [optional]
@@ -636,21 +636,23 @@ class Verta extends DateTime {
*/ */
public function __get($name) public function __get($name)
{ {
static $formats = array(
'year' => 'Y',
'month' => 'n',
'day' => 'j',
'hour' => 'G',
'minute' => 'i',
'second' => 's',
'micro' => 'u',
'dayOfWeek' => 'w',
'dayOfYear' => 'z',
'weekOfYear' => 'W',
'daysInMonth' => 't',
'timestamp' => 'U',
);
switch (true) { switch (true) {
case array_key_exists($name, $formats = array( case isset($formats[$name]):
'year' => 'Y',
'month' => 'n',
'day' => 'j',
'hour' => 'G',
'minute' => 'i',
'second' => 's',
'micro' => 'u',
'dayOfWeek' => 'w',
'dayOfYear' => 'z',
'weekOfYear' => 'W',
'daysInMonth' => 't',
'timestamp' => 'U',
)):
return (int) $this->format($formats[$name]); return (int) $this->format($formats[$name]);
case $name === 'quarter': case $name === 'quarter':
@@ -880,7 +882,7 @@ class Verta extends DateTime {
return $this->setTime($hour, $minute, $second, 0); return $this->setTime($hour, $minute, $second, 0);
} }
/***************************** STRING FORMATED ****************************/ /***************************** STRING FORMATED ****************************/
/** /**
* Reset the format used to the default when type juggling a Verta instance to a string * Reset the format used to the default when type juggling a Verta instance to a string
@@ -910,13 +912,13 @@ class Verta extends DateTime {
return $this->format(static::$stringFormat); return $this->format(static::$stringFormat);
} }
/** /**
* The format of the outputted date string (jalali equivalent of php date() function) * The format of the outputted date string (jalali equivalent of php date() function)
* *
* @param string $format for example 'Y-m-d H:i:s' * @param string $format for example 'Y-m-d H:i:s'
* @return string * @return string
*/ */
protected function date($format){ protected function date($format){
$timestamp = $this->getTimestamp(); $timestamp = $this->getTimestamp();
@@ -1065,7 +1067,7 @@ class Verta extends DateTime {
$i++; $i++;
} }
return $result; return $result;
} }
/** /**
* The format of the outputted date string (jalali equivalent of php date() function) * The format of the outputted date string (jalali equivalent of php date() function)
@@ -1237,9 +1239,9 @@ class Verta extends DateTime {
return ($days + $day); return ($days + $day);
} }
/** /**
* The format of the outputted date string (jalali equivalent of php strftime() function) * The format of the outputted date string (jalali equivalent of php strftime() function)
* *
* @param $format * @param $format
* @return string * @return string
*/ */
@@ -1435,7 +1437,7 @@ class Verta extends DateTime {
return $this->dateWord($this->strftime($format)); return $this->dateWord($this->strftime($format));
} }
/** /**
* Convert english numbers to persian numbers * Convert english numbers to persian numbers
* *
* @param string $string * @param string $string
@@ -1449,18 +1451,18 @@ class Verta extends DateTime {
/***************************** COMPERTION ****************************/ /***************************** COMPERTION ****************************/
/** /**
* check jalali the instance is a leap year * check jalali the instance is a leap year
* *
* @param int $year * @param int $year
* @return bool * @return bool
*/ */
public static function isLeapYear($year) { public static function isLeapYear($year) {
$mod = ($year % 33); $mod = ($year % 33);
if (($mod == 1) or ( $mod == 5) or ( $mod == 9) or ( $mod == 13) or ( $mod == 17) or ( $mod == 22) or ( $mod == 26) or ( $mod == 30)) { if (($mod == 1) or ( $mod == 5) or ( $mod == 9) or ( $mod == 13) or ( $mod == 17) or ( $mod == 22) or ( $mod == 26) or ( $mod == 30)) {
return true; return true;
} }
return false; return false;
} }
/** /**
* validate a jalali date (jalali equivalent of php checkdate() function) * validate a jalali date (jalali equivalent of php checkdate() function)
@@ -1473,8 +1475,8 @@ class Verta extends DateTime {
public static function isValideDate($year, $month, $day) { public static function isValideDate($year, $month, $day) {
$dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month)-1]; $dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month)-1];
return $year >= 1 && $year <= 32766 return $year >= 1 && $year <= 32766
&& $month >= 1 && $month <= 12 && $month >= 1 && $month <= 12
&& $day >= 1 && $day <= $dayLastMonthJalali; && $day >= 1 && $day <= $dayLastMonthJalali;
} }
/** /**
@@ -1487,8 +1489,8 @@ class Verta extends DateTime {
*/ */
public static function isValideTime($hour, $minute, $second) { public static function isValideTime($hour, $minute, $second) {
return $hour >= 0 && $hour <= 24 return $hour >= 0 && $hour <= 24
&& $minute >= 0 && $minute <= 59 && $minute >= 0 && $minute <= 59
&& $second >= 0 && $second <= 59; && $second >= 0 && $second <= 59;
} }
/** /**
@@ -2302,7 +2304,7 @@ class Verta extends DateTime {
return $this->addDays(-1 * $value); return $this->addDays(-1 * $value);
} }
/** /**
* Add weeks to the instance. Positive $value travels forward while * Add weeks to the instance. Positive $value travels forward while
* negative $value travels into the past. * negative $value travels into the past.
* *