Fix styling
This commit is contained in:
1 parent
145ce06288
commit
7a0be8a936
29 files changed
+248
-250
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
{"php":"8.1.1","version":"3.5.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_opening_tag":true,"braces":{"allow_single_line_anonymous_class_with_empty_body":true},"class_definition":{"space_before_parenthesis":true},"compact_nullable_typehint":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"sort_algorithm":"alpha"},"return_type_declaration":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}}},"hashes":{"src\/Traits\/Translator.php":448542714,"src\/Traits\/Comparison.php":3926327020,"src\/Traits\/Boundaries.php":177542658,"src\/Traits\/Creator.php":1689858777,"src\/Traits\/Formatting.php":113682988,"src\/Traits\/Accessor.php":3672088395,"src\/Traits\/Difference.php":1846129813,"src\/Traits\/Modification.php":1289161807,"src\/Traits\/Transformation.php":2767394386,"src\/Traits\/Date.php":337576065,"src\/VertaInterface.php":2606416261,"src\/Verta.php":1398063567,"src\/Lang\/ps.php":1557833854,"src\/Lang\/en.php":4059164324,"src\/Lang\/haz.php":67156656,"src\/Lang\/ku.php":1336513500,"src\/Lang\/az.php":722372108,"src\/Lang\/fa.php":1662853050,"src\/Lang\/ar.php":1426472215,"src\/helpers.php":2970057840,"src\/Laravel\/VertaServiceProvider.php":3527274115,"src\/Laravel\/JalaliValidator.php":539122976,"src\/Facades\/Verta.php":8857523,"tests\/ComparisionTest.php":1311523399,"tests\/AccessTest.php":434586276,"tests\/CreatorTest.php":4251091983,"tests\/FormatTest.php":1791904145,"tests\/bootstrap.php":2741744302,"tests\/ModificationTest.php":966836384}}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Facades;
|
namespace Hekmatinasser\Verta\Facades;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|||||||
+2
-3
@@ -45,7 +45,7 @@ return [
|
|||||||
'month' => 'شهر',
|
'month' => 'شهر',
|
||||||
'yaer' => 'سنة',
|
'yaer' => 'سنة',
|
||||||
'decade' => 'عشر سنوات',
|
'decade' => 'عشر سنوات',
|
||||||
'century' => 'مئة عام'
|
'century' => 'مئة عام',
|
||||||
],
|
],
|
||||||
'phrase' => [
|
'phrase' => [
|
||||||
'am' => 'ق ظ',
|
'am' => 'ق ظ',
|
||||||
@@ -78,6 +78,5 @@ return [
|
|||||||
'2' => 'الصيف',
|
'2' => 'الصيف',
|
||||||
'3' => 'الخريف',
|
'3' => 'الخريف',
|
||||||
'4' => 'شتاء',
|
'4' => 'شتاء',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
+2
-3
@@ -45,7 +45,7 @@ return [
|
|||||||
'month' => 'ماه',
|
'month' => 'ماه',
|
||||||
'yaer' => 'سال',
|
'yaer' => 'سال',
|
||||||
'decade' => 'دهه',
|
'decade' => 'دهه',
|
||||||
'century' => 'قرن'
|
'century' => 'قرن',
|
||||||
],
|
],
|
||||||
'phrase' => [
|
'phrase' => [
|
||||||
'am' => 'ق ظ',
|
'am' => 'ق ظ',
|
||||||
@@ -78,6 +78,5 @@ return [
|
|||||||
'2' => 'تابستان',
|
'2' => 'تابستان',
|
||||||
'3' => 'پاییز',
|
'3' => 'پاییز',
|
||||||
'4' => 'زمستان',
|
'4' => 'زمستان',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
+2
-3
@@ -45,7 +45,7 @@ return [
|
|||||||
'month' => 'month',
|
'month' => 'month',
|
||||||
'yaer' => 'yaer',
|
'yaer' => 'yaer',
|
||||||
'decade' => 'decade',
|
'decade' => 'decade',
|
||||||
'century' => 'century'
|
'century' => 'century',
|
||||||
],
|
],
|
||||||
'phrase' => [
|
'phrase' => [
|
||||||
'am' => 'am',
|
'am' => 'am',
|
||||||
@@ -78,6 +78,5 @@ return [
|
|||||||
'2' => 'summer',
|
'2' => 'summer',
|
||||||
'3' => 'autumn',
|
'3' => 'autumn',
|
||||||
'4' => 'winter',
|
'4' => 'winter',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
+2
-3
@@ -45,7 +45,7 @@ return [
|
|||||||
'month' => 'ماه',
|
'month' => 'ماه',
|
||||||
'yaer' => 'سال',
|
'yaer' => 'سال',
|
||||||
'decade' => 'دهه',
|
'decade' => 'دهه',
|
||||||
'century' => 'قرن'
|
'century' => 'قرن',
|
||||||
],
|
],
|
||||||
'phrase' => [
|
'phrase' => [
|
||||||
'am' => 'ق ظ',
|
'am' => 'ق ظ',
|
||||||
@@ -78,6 +78,5 @@ return [
|
|||||||
'2' => 'تابستان',
|
'2' => 'تابستان',
|
||||||
'3' => 'پاییز',
|
'3' => 'پاییز',
|
||||||
'4' => 'زمستان',
|
'4' => 'زمستان',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
+2
-3
@@ -45,7 +45,7 @@ return [
|
|||||||
'month' => 'ماه',
|
'month' => 'ماه',
|
||||||
'yaer' => 'سال',
|
'yaer' => 'سال',
|
||||||
'decade' => 'دهه',
|
'decade' => 'دهه',
|
||||||
'century' => 'قرن'
|
'century' => 'قرن',
|
||||||
],
|
],
|
||||||
'phrase' => [
|
'phrase' => [
|
||||||
'am' => 'ق ظ',
|
'am' => 'ق ظ',
|
||||||
@@ -78,6 +78,5 @@ return [
|
|||||||
'2' => 'تابستان',
|
'2' => 'تابستان',
|
||||||
'3' => 'پاییز',
|
'3' => 'پاییز',
|
||||||
'4' => 'زمستان',
|
'4' => 'زمستان',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
+2
-3
@@ -45,7 +45,7 @@ return [
|
|||||||
'month' => 'ماه',
|
'month' => 'ماه',
|
||||||
'yaer' => 'سال',
|
'yaer' => 'سال',
|
||||||
'decade' => 'دهه',
|
'decade' => 'دهه',
|
||||||
'century' => 'قرن'
|
'century' => 'قرن',
|
||||||
],
|
],
|
||||||
'phrase' => [
|
'phrase' => [
|
||||||
'am' => 'ق ظ',
|
'am' => 'ق ظ',
|
||||||
@@ -78,6 +78,5 @@ return [
|
|||||||
'2' => 'تابستان',
|
'2' => 'تابستان',
|
||||||
'3' => 'پاییز',
|
'3' => 'پاییز',
|
||||||
'4' => 'زمستان',
|
'4' => 'زمستان',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
+2
-3
@@ -44,7 +44,7 @@ return [
|
|||||||
'week' => 'هفته',
|
'week' => 'هفته',
|
||||||
'month' => 'ماه',
|
'month' => 'ماه',
|
||||||
'yaer' => 'سال',
|
'yaer' => 'سال',
|
||||||
'century' => 'قرن'
|
'century' => 'قرن',
|
||||||
],
|
],
|
||||||
'phrase' => [
|
'phrase' => [
|
||||||
'am' => 'ق ظ',
|
'am' => 'ق ظ',
|
||||||
@@ -77,6 +77,5 @@ return [
|
|||||||
'2' => 'تابستان',
|
'2' => 'تابستان',
|
||||||
'3' => 'پاییز',
|
'3' => 'پاییز',
|
||||||
'4' => 'زمستان',
|
'4' => 'زمستان',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -3,33 +3,35 @@
|
|||||||
namespace Hekmatinasser\Verta\Laravel;
|
namespace Hekmatinasser\Verta\Laravel;
|
||||||
|
|
||||||
use Hekmatinasser\Verta\Verta;
|
use Hekmatinasser\Verta\Verta;
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use phpDocumentor\Reflection\Types\Static_;
|
|
||||||
|
|
||||||
class JalaliValidator
|
class JalaliValidator
|
||||||
{
|
{
|
||||||
public function validateDate($attribute, $value, $parameters)
|
public function validateDate($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) ? $parameters[0] : 'Y/m/d';
|
$format = count($parameters) ? $parameters[0] : 'Y/m/d';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Verta::parseFormat($format, $value);
|
Verta::parseFormat($format, $value);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateDateEqual($attribute, $value, $parameters)
|
public function validateDateEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->eq($base);
|
return Verta::parseFormat($format, $value)->eq($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -38,12 +40,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateNotEqual($attribute, $value, $parameters)
|
public function validateDateNotEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->ne($base);
|
return Verta::parseFormat($format, $value)->ne($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -52,27 +56,31 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateTime($attribute, $value, $parameters)
|
public function validateDateTime($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$format = count($parameters) ? $parameters[0] : 'Y/m/d H:i:s';
|
$format = count($parameters) ? $parameters[0] : 'Y/m/d H:i:s';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Verta::parseFormat($format, $value);
|
Verta::parseFormat($format, $value);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateDateTimeEqual($attribute, $value, $parameters)
|
public function validateDateTimeEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->eq($base);
|
return Verta::parseFormat($format, $value)->eq($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -81,12 +89,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateTimeNotEqual($attribute, $value, $parameters)
|
public function validateDateTimeNotEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->ne($base);
|
return Verta::parseFormat($format, $value)->ne($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -95,12 +105,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateAfter($attribute, $value, $parameters)
|
public function validateDateAfter($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->gt($base);
|
return Verta::parseFormat($format, $value)->gt($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -109,12 +121,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateAfterEqual($attribute, $value, $parameters)
|
public function validateDateAfterEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->gte($base);
|
return Verta::parseFormat($format, $value)->gte($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -123,12 +137,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateTimeAfter($attribute, $value, $parameters)
|
public function validateDateTimeAfter($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->gt($base);
|
return Verta::parseFormat($format, $value)->gt($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -137,12 +153,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateTimeAfterEqual($attribute, $value, $parameters)
|
public function validateDateTimeAfterEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->gte($base);
|
return Verta::parseFormat($format, $value)->gte($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -151,12 +169,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateBefore($attribute, $value, $parameters)
|
public function validateDateBefore($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->lt($base);
|
return Verta::parseFormat($format, $value)->lt($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -165,12 +185,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateBeforeEqual($attribute, $value, $parameters)
|
public function validateDateBeforeEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->lte($base);
|
return Verta::parseFormat($format, $value)->lte($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -179,12 +201,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateTimeBefore($attribute, $value, $parameters)
|
public function validateDateTimeBefore($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->lt($base);
|
return Verta::parseFormat($format, $value)->lt($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -193,12 +217,14 @@ class JalaliValidator
|
|||||||
|
|
||||||
public function validateDateTimeBeforeEqual($attribute, $value, $parameters)
|
public function validateDateTimeBeforeEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (! is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
$base = count($parameters) > 0 ? Verta::parseFormat($format, $parameters[0]) : null;
|
||||||
|
|
||||||
return Verta::parseFormat($format, $value)->lte($base);
|
return Verta::parseFormat($format, $value)->lte($base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -214,11 +240,12 @@ class JalaliValidator
|
|||||||
{
|
{
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
||||||
if(Verta::getLocale() != 'en') {
|
if (Verta::getLocale() != 'en') {
|
||||||
$en = Verta::getMessages('en');
|
$en = Verta::getMessages('en');
|
||||||
$to = Verta::getMessages();
|
$to = Verta::getMessages();
|
||||||
$date = str_replace(array_values($en['numbers']), array_values($to['numbers']), $date);
|
$date = str_replace(array_values($en['numbers']), array_values($to['numbers']), $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
return str_replace(':date', $date, $message);
|
return str_replace(':date', $date, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,11 +253,12 @@ class JalaliValidator
|
|||||||
{
|
{
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
$date = count($parameters) ? $parameters[0] : Verta::instance()->format($format);
|
||||||
if(Verta::getLocale() != 'en') {
|
if (Verta::getLocale() != 'en') {
|
||||||
$en = Verta::getMessages('en');
|
$en = Verta::getMessages('en');
|
||||||
$to = Verta::getMessages();
|
$to = Verta::getMessages();
|
||||||
$date = str_replace(array_values($en['numbers']), array_values($to['numbers']), $date);
|
$date = str_replace(array_values($en['numbers']), array_values($to['numbers']), $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
return str_replace(':date', $date, $message);
|
return str_replace(':date', $date, $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,63 +8,62 @@ use Illuminate\Support\ServiceProvider;
|
|||||||
|
|
||||||
class VertaServiceProvider extends ServiceProvider
|
class VertaServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
private $rules = [
|
private $rules = [
|
||||||
'jdate' => [
|
'jdate' => [
|
||||||
'extend' => 'validateDate',
|
'extend' => 'validateDate',
|
||||||
'replacer' => 'replaceDateOrDatetime'
|
'replacer' => 'replaceDateOrDatetime',
|
||||||
],
|
],
|
||||||
'jdate_equal' => [
|
'jdate_equal' => [
|
||||||
'extend' => 'validateDateEqual',
|
'extend' => 'validateDateEqual',
|
||||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdate_not_equal' => [
|
'jdate_not_equal' => [
|
||||||
'extend' => 'validateDateNotEqual',
|
'extend' => 'validateDateNotEqual',
|
||||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdatetime' => [
|
'jdatetime' => [
|
||||||
'extend' => 'validateDateTime',
|
'extend' => 'validateDateTime',
|
||||||
'replacer' => 'replaceDateOrDatetime'
|
'replacer' => 'replaceDateOrDatetime',
|
||||||
],
|
],
|
||||||
'jdatetime_equal' => [
|
'jdatetime_equal' => [
|
||||||
'extend' => 'validateDateTimeEqual',
|
'extend' => 'validateDateTimeEqual',
|
||||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdatetime_not_equal' => [
|
'jdatetime_not_equal' => [
|
||||||
'extend' => 'validateDateTimeNotEqual',
|
'extend' => 'validateDateTimeNotEqual',
|
||||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdate_after' => [
|
'jdate_after' => [
|
||||||
'extend' => 'validateDateAfter',
|
'extend' => 'validateDateAfter',
|
||||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdate_after_equal' => [
|
'jdate_after_equal' => [
|
||||||
'extend' => 'validateDateAfterEqual',
|
'extend' => 'validateDateAfterEqual',
|
||||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdatetime_after' => [
|
'jdatetime_after' => [
|
||||||
'extend' => 'validateDateTimeAfter',
|
'extend' => 'validateDateTimeAfter',
|
||||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdatetime_after_equal' => [
|
'jdatetime_after_equal' => [
|
||||||
'extend' => 'validateDateTimeAfterEqual',
|
'extend' => 'validateDateTimeAfterEqual',
|
||||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdate_before' => [
|
'jdate_before' => [
|
||||||
'extend' => 'validateDateBefore',
|
'extend' => 'validateDateBefore',
|
||||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdate_before_equal' => [
|
'jdate_before_equal' => [
|
||||||
'extend' => 'validateDateBeforeEqual',
|
'extend' => 'validateDateBeforeEqual',
|
||||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdatetime_before' => [
|
'jdatetime_before' => [
|
||||||
'extend' => 'validateDateTimeBefore',
|
'extend' => 'validateDateTimeBefore',
|
||||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
'jdatetime_before_equal' => [
|
'jdatetime_before_equal' => [
|
||||||
'extend' => 'validateDateTimeBeforeEqual',
|
'extend' => 'validateDateTimeBeforeEqual',
|
||||||
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual'
|
'replacer' => 'replaceDateTimeAfterOrBeforeOrEqual',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -86,11 +85,10 @@ class VertaServiceProvider extends ServiceProvider
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->bind('verta', function ($app) {
|
$this->app->bind('verta', function ($app) {
|
||||||
return new Verta;
|
return new Verta();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the services provided by the provider.
|
* Get the services provided by the provider.
|
||||||
*
|
*
|
||||||
@@ -98,7 +96,7 @@ class VertaServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function provides()
|
public function provides()
|
||||||
{
|
{
|
||||||
return array('verta');
|
return ['verta'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadValidators()
|
public function loadValidators()
|
||||||
@@ -106,9 +104,7 @@ class VertaServiceProvider extends ServiceProvider
|
|||||||
$className = JalaliValidator::class . '@';
|
$className = JalaliValidator::class . '@';
|
||||||
|
|
||||||
foreach ($this->rules as $name => $methods) {
|
foreach ($this->rules as $name => $methods) {
|
||||||
|
|
||||||
if (array_key_exists('extend', $methods) || array_key_exists('replacer', $methods)) {
|
if (array_key_exists('extend', $methods) || array_key_exists('replacer', $methods)) {
|
||||||
|
|
||||||
Validator::extend($name, $className . $methods['extend']);
|
Validator::extend($name, $className . $methods['extend']);
|
||||||
|
|
||||||
Validator::replacer($name, $className . $methods['replacer']);
|
Validator::replacer($name, $className . $methods['replacer']);
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
use Hekmatinasser\Verta\Verta;
|
use Hekmatinasser\Verta\Verta;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
trait Accessor
|
trait Accessor
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a part of the Verta object
|
* Get a part of the Verta object
|
||||||
*
|
*
|
||||||
@@ -22,7 +19,7 @@ trait Accessor
|
|||||||
*/
|
*/
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
static $formats = array(
|
static $formats = [
|
||||||
'year' => 'Y',
|
'year' => 'Y',
|
||||||
'month' => 'n',
|
'month' => 'n',
|
||||||
'day' => 'j',
|
'day' => 'j',
|
||||||
@@ -35,7 +32,7 @@ trait Accessor
|
|||||||
'weekOfYear' => 'W',
|
'weekOfYear' => 'W',
|
||||||
'daysInMonth' => 't',
|
'daysInMonth' => 't',
|
||||||
'timestamp' => 'U',
|
'timestamp' => 'U',
|
||||||
);
|
];
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case isset($formats[$name]):
|
case isset($formats[$name]):
|
||||||
@@ -90,15 +87,18 @@ trait Accessor
|
|||||||
list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-n-j-G-i-s'));
|
list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-n-j-G-i-s'));
|
||||||
$$name = $value;
|
$$name = $value;
|
||||||
$this->setDateTime($year, $month, $day, $hour, $minute, $second);
|
$this->setDateTime($year, $month, $day, $hour, $minute, $second);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'timestamp':
|
case 'timestamp':
|
||||||
$this->setTimestamp($value);
|
$this->setTimestamp($value);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'timezone':
|
case 'timezone':
|
||||||
case 'tz':
|
case 'tz':
|
||||||
$this->setTimezone(new DateTimeZone($value));
|
$this->setTimezone(new DateTimeZone($value));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -268,5 +268,4 @@ trait Accessor
|
|||||||
|
|
||||||
return $this->setTime($hour, $minute, $second, 0);
|
return $this->setTime($hour, $minute, $second, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
trait Boundaries
|
trait Boundaries
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -159,5 +157,4 @@ trait Boundaries
|
|||||||
|
|
||||||
return $this->setDateTime($this->year, 12, $day, 23, 59, 59);
|
return $this->setDateTime($this->year, 12, $day, 23, 59, 59);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+15
-15
@@ -1,22 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
use Hekmatinasser\Verta\Verta;
|
use Hekmatinasser\Verta\Verta;
|
||||||
|
|
||||||
trait Comparison
|
trait Comparison
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)
|
||||||
return in_array(($year % 33) , [1 , 5 , 9 , 13 ,17 , 22 , 26 , 30]);
|
{
|
||||||
|
return in_array(($year % 33), [1 , 5 , 9 , 13 ,17 , 22 , 26 , 30]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,17 +25,19 @@ trait Comparison
|
|||||||
* @param int $year
|
* @param int $year
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isValidDate($year, $month, $day) {
|
public static function isValidDate($year, $month, $day)
|
||||||
if($year < 0 || $year > 32766) {
|
{
|
||||||
|
if ($year < 0 || $year > 32766) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($month < 1 || $month > 12) {
|
if ($month < 1 || $month > 12) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month)-1];
|
$dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month) - 1];
|
||||||
if($day < 1 || $day > $dayLastMonthJalali) {
|
if ($day < 1 || $day > $dayLastMonthJalali) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,8 @@ trait Comparison
|
|||||||
* @param int $second
|
* @param int $second
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isValidTime($hour, $minute, $second) {
|
public static function isValidTime($hour, $minute, $second)
|
||||||
|
{
|
||||||
return $hour >= 0 && $hour <= 23
|
return $hour >= 0 && $hour <= 23
|
||||||
&& $minute >= 0 && $minute <= 59
|
&& $minute >= 0 && $minute <= 59
|
||||||
&& $second >= 0 && $second <= 59;
|
&& $second >= 0 && $second <= 59;
|
||||||
@@ -90,7 +91,7 @@ trait Comparison
|
|||||||
*/
|
*/
|
||||||
public function ne(Verta $v = null)
|
public function ne(Verta $v = null)
|
||||||
{
|
{
|
||||||
return !$this->eq($v);
|
return ! $this->eq($v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -324,7 +325,7 @@ trait Comparison
|
|||||||
*/
|
*/
|
||||||
public function isWeekday()
|
public function isWeekday()
|
||||||
{
|
{
|
||||||
return !$this->isWeekend();
|
return ! $this->isWeekend();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -372,7 +373,7 @@ trait Comparison
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isNextWeek() : bool
|
public function isNextWeek(): bool
|
||||||
{
|
{
|
||||||
return $this->weekOfYear === static::now($this->getTimezone())->addWeek()->weekOfYear;
|
return $this->weekOfYear === static::now($this->getTimezone())->addWeek()->weekOfYear;
|
||||||
}
|
}
|
||||||
@@ -602,5 +603,4 @@ trait Comparison
|
|||||||
{
|
{
|
||||||
return $this->dayOfWeek === static::FRIDAY;
|
return $this->dayOfWeek === static::FRIDAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+34
-35
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
@@ -10,7 +9,6 @@ use InvalidArgumentException;
|
|||||||
|
|
||||||
trait Creator
|
trait Creator
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create object of Jalali
|
* create object of Jalali
|
||||||
*
|
*
|
||||||
@@ -20,16 +18,13 @@ trait Creator
|
|||||||
*/
|
*/
|
||||||
public function __construct($datetime = null, $timezone = null)
|
public function __construct($datetime = null, $timezone = null)
|
||||||
{
|
{
|
||||||
if(empty($datetime)) {
|
if (empty($datetime)) {
|
||||||
$datetime = 'now';
|
$datetime = 'now';
|
||||||
}
|
} elseif (is_string($datetime)) {
|
||||||
elseif (is_string($datetime)) {
|
|
||||||
$datetime = self::faToEnNumbers(self::arToEnNumbers($datetime));
|
$datetime = self::faToEnNumbers(self::arToEnNumbers($datetime));
|
||||||
}
|
} elseif ($datetime instanceof DateTime) {
|
||||||
elseif ($datetime instanceof DateTime) {
|
|
||||||
$datetime = "@{$datetime->getTimestamp()}";
|
$datetime = "@{$datetime->getTimestamp()}";
|
||||||
}
|
} elseif (is_int($datetime)) {
|
||||||
elseif (is_int($datetime)) {
|
|
||||||
$datetime = "@$datetime";
|
$datetime = "@$datetime";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +44,8 @@ trait Creator
|
|||||||
* @param null $timezone
|
* @param null $timezone
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function now($timezone = null) {
|
public static function now($timezone = null)
|
||||||
|
{
|
||||||
return new static(null, $timezone);
|
return new static(null, $timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +56,6 @@ trait Creator
|
|||||||
*
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function today($timezone = null)
|
public static function today($timezone = null)
|
||||||
{
|
{
|
||||||
return (new static($timezone))->startDay();
|
return (new static($timezone))->startDay();
|
||||||
@@ -98,7 +93,8 @@ trait Creator
|
|||||||
*
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function instance($datetime = null, $timezone = null) {
|
public static function instance($datetime = null, $timezone = null)
|
||||||
|
{
|
||||||
return new static($datetime, $timezone);
|
return new static($datetime, $timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +123,8 @@ trait Creator
|
|||||||
*
|
*
|
||||||
* @return datetime $datetime
|
* @return datetime $datetime
|
||||||
*/
|
*/
|
||||||
public function datetime() {
|
public function datetime()
|
||||||
|
{
|
||||||
return new DateTime(date('Y-m-d H:i:s', $this->getTimestamp()), $this->getTimezone());
|
return new DateTime(date('Y-m-d H:i:s', $this->getTimestamp()), $this->getTimezone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,23 +136,28 @@ trait Creator
|
|||||||
*
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function parse($datetime , $timezone = null)
|
public static function parse($datetime, $timezone = null)
|
||||||
{
|
{
|
||||||
self::loadMessages();
|
self::loadMessages();
|
||||||
$names = array_map(function ($value) { return " $value "; }, array_values(self::$messages['year_months']));
|
$names = array_map(function ($value) {
|
||||||
$values = array_map(function ($value) { return "-$value-"; }, range(1,12));
|
return " $value ";
|
||||||
|
}, array_values(self::$messages['year_months']));
|
||||||
|
$values = array_map(function ($value) {
|
||||||
|
return "-$value-";
|
||||||
|
}, range(1, 12));
|
||||||
|
|
||||||
$formatted = str_replace($names, $values, $datetime);
|
$formatted = str_replace($names, $values, $datetime);
|
||||||
$formatted = str_replace(array_values(self::$messages['year_months']), range(1,12), $formatted);
|
$formatted = str_replace(array_values(self::$messages['year_months']), range(1, 12), $formatted);
|
||||||
$parse = date_parse($formatted);
|
$parse = date_parse($formatted);
|
||||||
if($parse['error_count'] > 0 || !self::isValidDate($parse['year'], $parse['month'], $parse['day']) || !self::isValidTime($parse['hour'], $parse['minute'], $parse['second'])) {
|
if ($parse['error_count'] > 0 || ! self::isValidDate($parse['year'], $parse['month'], $parse['day']) || ! self::isValidTime($parse['hour'], $parse['minute'], $parse['second'])) {
|
||||||
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
|
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
|
||||||
}
|
}
|
||||||
|
|
||||||
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
|
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
|
||||||
list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);
|
list($hour, $minute, $second) = [$parse['hour'], $parse['minute'], $parse['second']];
|
||||||
|
|
||||||
$datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second);
|
$datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second);
|
||||||
|
|
||||||
return new static($datetime, $timezone);
|
return new static($datetime, $timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,16 +172,17 @@ trait Creator
|
|||||||
public static function parseFormat($format, $datetime, $timezone = null)
|
public static function parseFormat($format, $datetime, $timezone = null)
|
||||||
{
|
{
|
||||||
self::loadMessages();
|
self::loadMessages();
|
||||||
$formatted = str_replace(array_values(self::$messages['year_months']), range(1,12), $datetime);
|
$formatted = str_replace(array_values(self::$messages['year_months']), range(1, 12), $datetime);
|
||||||
|
|
||||||
$parse = date_parse_from_format($format, $formatted);
|
$parse = date_parse_from_format($format, $formatted);
|
||||||
if($parse['error_count'] > 0 || !self::isValidDate($parse['year'], $parse['month'], $parse['day']) || !self::isValidTime($parse['hour'], $parse['minute'], $parse['second'])) {
|
if ($parse['error_count'] > 0 || ! self::isValidDate($parse['year'], $parse['month'], $parse['day']) || ! self::isValidTime($parse['hour'], $parse['minute'], $parse['second'])) {
|
||||||
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
|
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
|
||||||
}
|
}
|
||||||
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
|
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
|
||||||
list($hour,$minute, $second) = array($parse['hour'], $parse['minute'], $parse['second']);
|
list($hour, $minute, $second) = [$parse['hour'], $parse['minute'], $parse['second']];
|
||||||
|
|
||||||
$datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second);
|
$datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second);
|
||||||
|
|
||||||
return new static($datetime, $timezone);
|
return new static($datetime, $timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,14 +254,13 @@ trait Creator
|
|||||||
* @param null $timezone
|
* @param null $timezone
|
||||||
* @return DateTimeZone|null
|
* @return DateTimeZone|null
|
||||||
*/
|
*/
|
||||||
protected static function createTimeZone($timezone = null) {
|
protected static function createTimeZone($timezone = null)
|
||||||
|
{
|
||||||
if ($timezone === null) {
|
if ($timezone === null) {
|
||||||
$tz = new DateTimeZone(date_default_timezone_get());
|
$tz = new DateTimeZone(date_default_timezone_get());
|
||||||
}
|
} elseif ($timezone instanceof DateTimeZone) {
|
||||||
elseif ($timezone instanceof DateTimeZone) {
|
|
||||||
$tz = $timezone;
|
$tz = $timezone;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$tz = @timezone_open(strval($timezone));
|
$tz = @timezone_open(strval($timezone));
|
||||||
if ($tz === false) {
|
if ($tz === false) {
|
||||||
throw new InvalidArgumentException(sprintf("Unknown timezone '%s'", $tz));
|
throw new InvalidArgumentException(sprintf("Unknown timezone '%s'", $tz));
|
||||||
@@ -286,18 +288,17 @@ trait Creator
|
|||||||
*/
|
*/
|
||||||
public static function createGregorian($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
|
public static function createGregorian($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$now = (new DateTime())->format('Y-n-j-G-i-s');
|
$now = (new DateTime())->format('Y-n-j-G-i-s');
|
||||||
$defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now));
|
$defaults = array_combine(['year', 'month', 'day', 'hour', 'minute', 'second'], explode('-', $now));
|
||||||
|
|
||||||
$year = $year ?? intval($defaults['year']);
|
$year = $year ?? intval($defaults['year']);
|
||||||
$month = $month ?? intval($defaults['month']);
|
$month = $month ?? intval($defaults['month']);
|
||||||
$day = $day ?? intval($defaults['day']);
|
$day = $day ?? intval($defaults['day']);
|
||||||
$hour = $hour ?? intval($defaults['hour']);
|
$hour = $hour ?? intval($defaults['hour']);
|
||||||
$minute = $minute ?? intval($defaults['minute']);
|
$minute = $minute ?? intval($defaults['minute']);
|
||||||
$second = $second ?? intval($defaults['second']);
|
$second = $second ?? intval($defaults['second']);
|
||||||
|
|
||||||
if (!checkdate($month, $day, $year) || !static::isValidTime($hour, $minute, $second)) {
|
if (! checkdate($month, $day, $year) || ! static::isValidTime($hour, $minute, $second)) {
|
||||||
throw new \InvalidArgumentException('Unknown datetime');
|
throw new \InvalidArgumentException('Unknown datetime');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,11 +351,10 @@ trait Creator
|
|||||||
*
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function createJalali($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
|
public static function createJalali($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
|
||||||
{
|
{
|
||||||
$now = (new static())->format('Y-n-j-G-i-s');
|
$now = (new static())->format('Y-n-j-G-i-s');
|
||||||
$defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now));
|
$defaults = array_combine(['year', 'month', 'day', 'hour', 'minute', 'second'], explode('-', $now));
|
||||||
|
|
||||||
$year = $year ?? intval($defaults['year']);
|
$year = $year ?? intval($defaults['year']);
|
||||||
$month = $month ?? intval($defaults['month']);
|
$month = $month ?? intval($defaults['month']);
|
||||||
@@ -363,7 +363,7 @@ trait Creator
|
|||||||
$minute = $minute ?? intval($defaults['minute']);
|
$minute = $minute ?? intval($defaults['minute']);
|
||||||
$second = $second ?? intval($defaults['second']);
|
$second = $second ?? intval($defaults['second']);
|
||||||
|
|
||||||
if (!static::isValidDate($year, $month, $day) || !static::isValidTime($hour, $minute, $second)) {
|
if (! static::isValidDate($year, $month, $day) || ! static::isValidTime($hour, $minute, $second)) {
|
||||||
throw new \InvalidArgumentException('Unknown datetime');
|
throw new \InvalidArgumentException('Unknown datetime');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,5 +399,4 @@ trait Creator
|
|||||||
{
|
{
|
||||||
return static::createJalali(null, null, null, $hour, $minute, $second, $timezone);
|
return static::createJalali(null, null, null, $hour, $minute, $second, $timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
use Hekmatinasser\Verta\VertaInterface;
|
use Hekmatinasser\Verta\VertaInterface;
|
||||||
|
|
||||||
trait Date
|
trait Date
|
||||||
@@ -59,5 +57,4 @@ trait Date
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $daysMonthJalali = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
|
protected static $daysMonthJalali = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
use Hekmatinasser\Verta\Verta;
|
use Hekmatinasser\Verta\Verta;
|
||||||
|
|
||||||
trait Difference
|
trait Difference
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the difference in years
|
* Get the difference in years
|
||||||
*
|
*
|
||||||
@@ -100,5 +97,4 @@ trait Difference
|
|||||||
|
|
||||||
return $v->getTimestamp() - $this->getTimestamp();
|
return $v->getTimestamp() - $this->getTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+49
-44
@@ -1,15 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
use Hekmatinasser\Notowo\Notowo;
|
use Hekmatinasser\Notowo\Notowo;
|
||||||
use Hekmatinasser\Verta\Verta;
|
use Hekmatinasser\Verta\Verta;
|
||||||
|
|
||||||
trait Formatting
|
trait Formatting
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
@@ -48,8 +45,8 @@ trait Formatting
|
|||||||
{
|
{
|
||||||
$timestamp = $this->getTimestamp();
|
$timestamp = $this->getTimestamp();
|
||||||
|
|
||||||
list( $gYear, $gMonth, $gDay, $gWeek ) = explode( '-', parent::format('Y-m-d-w'));
|
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w'));
|
||||||
list( $pYear, $pMonth, $pDay ) = static::getJalali( $gYear, $gMonth, $gDay );
|
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
|
||||||
|
|
||||||
$pWeek = $gWeek + 1;
|
$pWeek = $gWeek + 1;
|
||||||
|
|
||||||
@@ -62,29 +59,30 @@ trait Formatting
|
|||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
while ($index < $lengh) {
|
while ($index < $lengh) {
|
||||||
$char = $format[$index];
|
$char = $format[$index];
|
||||||
if ($char == '\\') {
|
if ($char == '\\') {
|
||||||
$result .= $format[++$index];
|
$result .= $format[++$index];
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$result .= $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
|
$result .= $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
|
||||||
|
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The format of the outputted date charactre (jalali equivalent of php date() function)
|
* The format of the outputted date charactre (jalali equivalent of php date() function)
|
||||||
*
|
*
|
||||||
* @param string $char
|
* @param string $char
|
||||||
* @param integer $timestamp
|
* @param int $timestamp
|
||||||
* @param integer $pYear
|
* @param int $pYear
|
||||||
* @param integer $pMonth
|
* @param int $pMonth
|
||||||
* @param integer $pDay
|
* @param int $pDay
|
||||||
* @param integer $pWeek
|
* @param int $pWeek
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek)
|
private function characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek)
|
||||||
@@ -92,62 +90,62 @@ trait Formatting
|
|||||||
switch ($char) {
|
switch ($char) {
|
||||||
# Day
|
# Day
|
||||||
case 'd':
|
case 'd':
|
||||||
return sprintf( '%02s', $pDay );
|
return sprintf('%02s', $pDay);
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
return substr( self::$messages['weekdays'][$pWeek+1], 0, 2 );
|
return substr(self::$messages['weekdays'][$pWeek + 1], 0, 2);
|
||||||
|
|
||||||
case 'j':
|
case 'j':
|
||||||
return $pDay;
|
return $pDay;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
return self::$messages['weekdays'][$pWeek+1];
|
return self::$messages['weekdays'][$pWeek + 1];
|
||||||
|
|
||||||
case 'N':
|
case 'N':
|
||||||
return $pWeek+1;
|
return $pWeek + 1;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
return $pWeek;
|
return $pWeek;
|
||||||
|
|
||||||
case 'z':
|
case 'z':
|
||||||
return $this->daysYear( $pMonth, $pDay );
|
return $this->daysYear($pMonth, $pDay);
|
||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
return static::$messages['phrase']['th'];
|
return static::$messages['phrase']['th'];
|
||||||
|
|
||||||
# Week
|
# Week
|
||||||
case 'W':
|
case 'W':
|
||||||
return ceil( $this->daysYear( $pMonth, $pDay ) / 7 );
|
return ceil($this->daysYear($pMonth, $pDay) / 7);
|
||||||
|
|
||||||
# Month
|
# Month
|
||||||
case 'F':
|
case 'F':
|
||||||
return self::$messages['year_months'][$pMonth];
|
return self::$messages['year_months'][$pMonth];
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
return sprintf( '%02s', $pMonth );
|
return sprintf('%02s', $pMonth);
|
||||||
|
|
||||||
case 'M':
|
case 'M':
|
||||||
return substr(self::$messages['year_months'][$pMonth], 0, 6 );
|
return substr(self::$messages['year_months'][$pMonth], 0, 6);
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
return $pMonth;
|
return $pMonth;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
return static::isLeapYear( $pYear ) && ( $pMonth == 12 ) ? 30 : static::$daysMonthJalali[ intval( $pMonth ) - 1 ];
|
return static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[ intval($pMonth) - 1 ];
|
||||||
# Quarter
|
# Quarter
|
||||||
case 'Q':
|
case 'Q':
|
||||||
case 'q':
|
case 'q':
|
||||||
return self::$messages['quarters'][$this->quarter];
|
return self::$messages['quarters'][$this->quarter];
|
||||||
# Years
|
# Years
|
||||||
case 'L':
|
case 'L':
|
||||||
return intval( $this->isLeapYear( $pYear ) );
|
return intval($this->isLeapYear($pYear));
|
||||||
|
|
||||||
case 'Y':
|
case 'Y':
|
||||||
case 'o':
|
case 'o':
|
||||||
return $pYear;
|
return $pYear;
|
||||||
|
|
||||||
case 'y':
|
case 'y':
|
||||||
return substr( $pYear, 2 );
|
return substr($pYear, 2);
|
||||||
|
|
||||||
# Time
|
# Time
|
||||||
case 'a':
|
case 'a':
|
||||||
@@ -171,14 +169,14 @@ trait Formatting
|
|||||||
case 'P':
|
case 'P':
|
||||||
case 'T':
|
case 'T':
|
||||||
case 'Z':
|
case 'Z':
|
||||||
return parent::format( $char );
|
return parent::format($char);
|
||||||
|
|
||||||
# Full Date/Time
|
# Full Date/Time
|
||||||
case 'c':
|
case 'c':
|
||||||
return ( $pYear . '-' . $pMonth . '-' . $pDay . ' ' . parent::format( 'H:i:s P' ) );
|
return ($pYear . '-' . $pMonth . '-' . $pDay . ' ' . parent::format('H:i:s P'));
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
return ( substr(self::$messages['weekdays'][$pWeek], 0, 2 ) . '، ' . $pDay . ' ' . substr(self::$messages['year_months'][$pMonth], 0, 6 ) . ' ' . $pYear . ' ' . parent::format( 'H:i:s P' ) );
|
return (substr(self::$messages['weekdays'][$pWeek], 0, 2) . '، ' . $pDay . ' ' . substr(self::$messages['year_months'][$pMonth], 0, 6) . ' ' . $pYear . ' ' . parent::format('H:i:s P'));
|
||||||
|
|
||||||
case 'U':
|
case 'U':
|
||||||
return $timestamp;
|
return $timestamp;
|
||||||
@@ -194,12 +192,12 @@ trait Formatting
|
|||||||
* @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 dateWord($format){
|
protected function dateWord($format)
|
||||||
|
{
|
||||||
$timestamp = $this->getTimestamp();
|
$timestamp = $this->getTimestamp();
|
||||||
|
|
||||||
list( $gYear, $gMonth, $gDay, $gWeek ) = explode( '-', parent::format('Y-m-d-w'));
|
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w'));
|
||||||
list( $pYear, $pMonth, $pDay ) = static::getJalali( $gYear, $gMonth, $gDay );
|
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
|
||||||
|
|
||||||
$pWeek = $gWeek + 1;
|
$pWeek = $gWeek + 1;
|
||||||
|
|
||||||
@@ -212,20 +210,22 @@ trait Formatting
|
|||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
while ($index < $lengh) {
|
while ($index < $lengh) {
|
||||||
$char = $format[$index];
|
$char = $format[$index];
|
||||||
if ($char == '\\') {
|
if ($char == '\\') {
|
||||||
$result .= $format[++$index];
|
$result .= $format[++$index];
|
||||||
$index++;
|
$index++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$output = $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
|
$output = $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
|
||||||
if(is_numeric($output)) {
|
if (is_numeric($output)) {
|
||||||
$output = (string) new Notowo($output, static::getLocale() == 'en' ? 'en' : 'fa' );
|
$output = (string) new Notowo($output, static::getLocale() == 'en' ? 'en' : 'fa');
|
||||||
}
|
}
|
||||||
$result .= $output;
|
$result .= $output;
|
||||||
|
|
||||||
$index++;
|
$index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,11 +237,13 @@ trait Formatting
|
|||||||
* @return type
|
* @return type
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*/
|
*/
|
||||||
protected function daysYear($month, $day) {
|
protected function daysYear($month, $day)
|
||||||
|
{
|
||||||
$days = 0;
|
$days = 0;
|
||||||
for ($i = 1; $i < $month; $i ++) {
|
for ($i = 1; $i < $month; $i++) {
|
||||||
$days += static::$daysMonthJalali[$i-1];
|
$days += static::$daysMonthJalali[$i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($days + $day);
|
return ($days + $day);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +255,7 @@ trait Formatting
|
|||||||
*/
|
*/
|
||||||
protected function strftime($format)
|
protected function strftime($format)
|
||||||
{
|
{
|
||||||
$strftime_date = array(
|
$strftime_date = [
|
||||||
"%a" => "D",
|
"%a" => "D",
|
||||||
"%A" => "l",
|
"%A" => "l",
|
||||||
"%d" => "d",
|
"%d" => "d",
|
||||||
@@ -295,8 +297,8 @@ trait Formatting
|
|||||||
"%t" => "\t",
|
"%t" => "\t",
|
||||||
"%%" => "%",
|
"%%" => "%",
|
||||||
"%Q" => "q",
|
"%Q" => "q",
|
||||||
"%q" => "q"
|
"%q" => "q",
|
||||||
);
|
];
|
||||||
|
|
||||||
return str_replace(array_keys($strftime_date), array_values($strftime_date), $format);
|
return str_replace(array_keys($strftime_date), array_values($strftime_date), $format);
|
||||||
}
|
}
|
||||||
@@ -307,7 +309,8 @@ trait Formatting
|
|||||||
* @param $format
|
* @param $format
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function format($format) {
|
public function format($format)
|
||||||
|
{
|
||||||
return $this->date($this->strftime($format));
|
return $this->date($this->strftime($format));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,8 +320,8 @@ trait Formatting
|
|||||||
* @param $format
|
* @param $format
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function formatGregorian($format) {
|
public function formatGregorian($format)
|
||||||
|
{
|
||||||
return $this->datetime()->format($format);
|
return $this->datetime()->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +404,7 @@ trait Formatting
|
|||||||
}
|
}
|
||||||
$difference = intval(round($difference));
|
$difference = intval(round($difference));
|
||||||
|
|
||||||
if($difference === 0) {
|
if ($difference === 0) {
|
||||||
return static::$messages['phrase']['now'];
|
return static::$messages['phrase']['now'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,6 +426,7 @@ trait Formatting
|
|||||||
{
|
{
|
||||||
$en = static::getMessages('en');
|
$en = static::getMessages('en');
|
||||||
$fa = static::getMessages('fa');
|
$fa = static::getMessages('fa');
|
||||||
|
|
||||||
return str_replace(array_values($en['numbers']), array_values($fa['numbers']), $string);
|
return str_replace(array_values($en['numbers']), array_values($fa['numbers']), $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,6 +440,7 @@ trait Formatting
|
|||||||
{
|
{
|
||||||
$fa = static::getMessages('fa');
|
$fa = static::getMessages('fa');
|
||||||
$en = static::getMessages('en');
|
$en = static::getMessages('en');
|
||||||
|
|
||||||
return str_replace(array_values($fa['numbers']), array_values($en['numbers']), $string);
|
return str_replace(array_values($fa['numbers']), array_values($en['numbers']), $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +454,7 @@ trait Formatting
|
|||||||
{
|
{
|
||||||
$ar = static::getMessages('ar');
|
$ar = static::getMessages('ar');
|
||||||
$en = static::getMessages('en');
|
$en = static::getMessages('en');
|
||||||
|
|
||||||
return str_replace(array_values($ar['numbers']), array_values($en['numbers']), $string);
|
return str_replace(array_values($ar['numbers']), array_values($en['numbers']), $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
use Hekmatinasser\Verta\Verta;
|
|
||||||
|
|
||||||
trait Modification
|
trait Modification
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add years to the instance. Positive $value travel forward while
|
* Add years to the instance. Positive $value travel forward while
|
||||||
* negative $value travel into the past.
|
* negative $value travel into the past.
|
||||||
@@ -73,23 +68,22 @@ trait Modification
|
|||||||
if ($month > 12) {
|
if ($month > 12) {
|
||||||
$year += intval($month / 12);
|
$year += intval($month / 12);
|
||||||
$month = $month % 12;
|
$month = $month % 12;
|
||||||
}
|
} elseif ($month < 1) {
|
||||||
elseif ($month < 1) {
|
|
||||||
$year += intval($month / 12) - 1;
|
$year += intval($month / 12) - 1;
|
||||||
$month = 12 + ($month % 12);
|
$month = 12 + ($month % 12);
|
||||||
}
|
}
|
||||||
if($month == 0) {
|
if ($month == 0) {
|
||||||
$year--;
|
$year--;
|
||||||
$month = 12;
|
$month = 12;
|
||||||
}
|
}
|
||||||
if (($month > 6 && $month < 12 && $day == 31)) {
|
if (($month > 6 && $month < 12 && $day == 31)) {
|
||||||
$day--;
|
$day--;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if ($month == 12 && ($day == 30 || $day == 31)) {
|
if ($month == 12 && ($day == 30 || $day == 31)) {
|
||||||
$day = self::isLeapYear($year) ? 30 : 29;
|
$day = self::isLeapYear($year) ? 30 : 29;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::createJalali($year, $month, $day, $hour, $minute, $second, $this->getTimeZone());
|
return self::createJalali($year, $month, $day, $hour, $minute, $second, $this->getTimeZone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
trait Transformation
|
trait Transformation
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gregorian to jalali convertion
|
* gregorian to jalali convertion
|
||||||
*
|
*
|
||||||
@@ -15,16 +12,18 @@ trait Transformation
|
|||||||
* @param int $g_d
|
* @param int $g_d
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getJalali($g_y, $g_m, $g_d) {
|
public static function getJalali($g_y, $g_m, $g_d)
|
||||||
|
{
|
||||||
$gy = $g_y - 1600;
|
$gy = $g_y - 1600;
|
||||||
$gm = $g_m - 1;
|
$gm = $g_m - 1;
|
||||||
$g_day_no = (365 * $gy + static::div($gy + 3, 4) - static::div($gy + 99, 100) + static::div($gy + 399, 400));
|
$g_day_no = (365 * $gy + static::div($gy + 3, 4) - static::div($gy + 99, 100) + static::div($gy + 399, 400));
|
||||||
for ($i = 0; $i < $gm; ++$i) {
|
for ($i = 0; $i < $gm; ++$i) {
|
||||||
$g_day_no += static::$daysMonthGregorian[$i];
|
$g_day_no += static::$daysMonthGregorian[$i];
|
||||||
}
|
}
|
||||||
if ($gm > 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0)))
|
if ($gm > 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0))) {
|
||||||
# leap and after Feb
|
# leap and after Feb
|
||||||
$g_day_no ++;
|
$g_day_no++;
|
||||||
|
}
|
||||||
$g_day_no += $g_d - 1;
|
$g_day_no += $g_d - 1;
|
||||||
$j_day_no = $g_day_no - 79;
|
$j_day_no = $g_day_no - 79;
|
||||||
$j_np = static::div($j_day_no, 12053); # 12053 = (365 * 33 + 32 / 4)
|
$j_np = static::div($j_day_no, 12053); # 12053 = (365 * 33 + 32 / 4)
|
||||||
@@ -38,7 +37,8 @@ trait Transformation
|
|||||||
for ($i = 0; ($i < 11 && $j_day_no >= static::$daysMonthJalali[$i]); ++$i) {
|
for ($i = 0; ($i < 11 && $j_day_no >= static::$daysMonthJalali[$i]); ++$i) {
|
||||||
$j_day_no -= static::$daysMonthJalali[$i];
|
$j_day_no -= static::$daysMonthJalali[$i];
|
||||||
}
|
}
|
||||||
return array($jy, $i + 1, $j_day_no + 1);
|
|
||||||
|
return [$jy, $i + 1, $j_day_no + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,7 +49,8 @@ trait Transformation
|
|||||||
* @param int $j_d
|
* @param int $j_d
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getGregorian($j_y, $j_m, $j_d) {
|
public static function getGregorian($j_y, $j_m, $j_d)
|
||||||
|
{
|
||||||
$jy = $j_y - 979;
|
$jy = $j_y - 979;
|
||||||
$jm = $j_m - 1;
|
$jm = $j_m - 1;
|
||||||
$j_day_no = (365 * $jy + static::div($jy, 33) * 8 + static::div($jy % 33 + 3, 4));
|
$j_day_no = (365 * $jy + static::div($jy, 33) * 8 + static::div($jy % 33 + 3, 4));
|
||||||
@@ -62,11 +63,11 @@ trait Transformation
|
|||||||
$g_day_no = $g_day_no % 146097;
|
$g_day_no = $g_day_no % 146097;
|
||||||
$leap = 1;
|
$leap = 1;
|
||||||
if ($g_day_no >= 36525) { # 36525 = (365 * 100 + 100 / 4)
|
if ($g_day_no >= 36525) { # 36525 = (365 * 100 + 100 / 4)
|
||||||
$g_day_no --;
|
$g_day_no--;
|
||||||
$gy += (100 * static::div($g_day_no, 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100)
|
$gy += (100 * static::div($g_day_no, 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100)
|
||||||
$g_day_no = $g_day_no % 36524;
|
$g_day_no = $g_day_no % 36524;
|
||||||
if ($g_day_no >= 365) {
|
if ($g_day_no >= 365) {
|
||||||
$g_day_no ++;
|
$g_day_no++;
|
||||||
} else {
|
} else {
|
||||||
$leap = 0;
|
$leap = 0;
|
||||||
}
|
}
|
||||||
@@ -75,14 +76,15 @@ trait Transformation
|
|||||||
$g_day_no %= 1461;
|
$g_day_no %= 1461;
|
||||||
if ($g_day_no >= 366) {
|
if ($g_day_no >= 366) {
|
||||||
$leap = 0;
|
$leap = 0;
|
||||||
$g_day_no --;
|
$g_day_no--;
|
||||||
$gy += static::div($g_day_no, 365);
|
$gy += static::div($g_day_no, 365);
|
||||||
$g_day_no = ($g_day_no % 365);
|
$g_day_no = ($g_day_no % 365);
|
||||||
}
|
}
|
||||||
for ($i = 0; $g_day_no >= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); $i ++) {
|
for ($i = 0; $g_day_no >= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); $i++) {
|
||||||
$g_day_no -= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap));
|
$g_day_no -= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap));
|
||||||
}
|
}
|
||||||
return array($gy, $i + 1, $g_day_no + 1);
|
|
||||||
|
return [$gy, $i + 1, $g_day_no + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +94,8 @@ trait Transformation
|
|||||||
* @param int $b
|
* @param int $b
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private static function div($a, $b) {
|
private static function div($a, $b)
|
||||||
|
{
|
||||||
return ~~($a / $b);
|
return ~~($a / $b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta\Traits;
|
namespace Hekmatinasser\Verta\Traits;
|
||||||
|
|
||||||
|
|
||||||
trait Translator
|
trait Translator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -11,7 +9,7 @@ trait Translator
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $messages = array();
|
public static $messages = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of custom localized messages.
|
* List of custom localized messages.
|
||||||
@@ -35,9 +33,10 @@ trait Translator
|
|||||||
*/
|
*/
|
||||||
public static function setLocale($locale)
|
public static function setLocale($locale)
|
||||||
{
|
{
|
||||||
if($messages = static::loadMessages($locale)) {
|
if ($messages = static::loadMessages($locale)) {
|
||||||
static::$locale = $locale;
|
static::$locale = $locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $messages;
|
return $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,13 +61,13 @@ trait Translator
|
|||||||
{
|
{
|
||||||
if ($messages = static::getMessages($locale)) {
|
if ($messages = static::getMessages($locale)) {
|
||||||
static::$messages = $messages;
|
static::$messages = $messages;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set messages of a locale and take file first if present.
|
* Set messages of a locale and take file first if present.
|
||||||
*
|
*
|
||||||
@@ -81,10 +80,10 @@ trait Translator
|
|||||||
if (file_exists($filename = dirname(__DIR__).'/Lang/'.($locale ?: static::getLocale()).'.php')) {
|
if (file_exists($filename = dirname(__DIR__).'/Lang/'.($locale ?: static::getLocale()).'.php')) {
|
||||||
return require $filename;
|
return require $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set messages of a locale and take file first if present.
|
* Set messages of a locale and take file first if present.
|
||||||
*
|
*
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@ namespace Hekmatinasser\Verta;
|
|||||||
use DateTime;
|
use DateTime;
|
||||||
use Hekmatinasser\Verta\Traits\Date;
|
use Hekmatinasser\Verta\Traits\Date;
|
||||||
|
|
||||||
class Verta extends DateTime implements VertaInterface {
|
class Verta extends DateTime implements VertaInterface
|
||||||
|
{
|
||||||
use Date;
|
use Date;
|
||||||
}
|
}
|
||||||
+19
-21
@@ -1,43 +1,41 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Hekmatinasser\Verta;
|
namespace Hekmatinasser\Verta;
|
||||||
|
|
||||||
|
|
||||||
interface VertaInterface
|
interface VertaInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The day constants
|
* The day constants
|
||||||
*/
|
*/
|
||||||
const SATURDAY = 0;
|
public const SATURDAY = 0;
|
||||||
const SUNDAY = 1;
|
public const SUNDAY = 1;
|
||||||
const MONDAY = 2;
|
public const MONDAY = 2;
|
||||||
const TUESDAY = 3;
|
public const TUESDAY = 3;
|
||||||
const WEDNESDAY = 4;
|
public const WEDNESDAY = 4;
|
||||||
const THURSDAY = 5;
|
public const THURSDAY = 5;
|
||||||
const FRIDAY = 6;
|
public const FRIDAY = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number unit in date
|
* Number unit in date
|
||||||
*/
|
*/
|
||||||
const DECADE_PER_CENTURY = 10;
|
public const DECADE_PER_CENTURY = 10;
|
||||||
const YEARS_PER_DECADE = 10;
|
public const YEARS_PER_DECADE = 10;
|
||||||
const MONTHS_PER_YEAR = 12;
|
public const MONTHS_PER_YEAR = 12;
|
||||||
const MONTHS_PER_QUARTER = 3;
|
public const MONTHS_PER_QUARTER = 3;
|
||||||
const WEEKS_PER_YEAR = 52;
|
public const WEEKS_PER_YEAR = 52;
|
||||||
const WEEKS_PER_MONTH = 4.35;
|
public const WEEKS_PER_MONTH = 4.35;
|
||||||
const DAYS_PER_WEEK = 7;
|
public const DAYS_PER_WEEK = 7;
|
||||||
const HOURS_PER_DAY = 24;
|
public const HOURS_PER_DAY = 24;
|
||||||
const MINUTES_PER_HOUR = 60;
|
public const MINUTES_PER_HOUR = 60;
|
||||||
const SECONDS_PER_MINUTE = 60;
|
public const SECONDS_PER_MINUTE = 60;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Word use in format datetime.
|
* Word use in format datetime.
|
||||||
*/
|
*/
|
||||||
const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s';
|
public const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Word use in format datetime.
|
* Word use in format datetime.
|
||||||
*/
|
*/
|
||||||
const DEFAULT_LOCALE = 'fa';
|
public const DEFAULT_LOCALE = 'fa';
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (! function_exists('verta')) {
|
if (! function_exists('verta')) {
|
||||||
/**
|
/**
|
||||||
* @param null $datetime
|
* @param null $datetime
|
||||||
|
|||||||
@@ -85,10 +85,9 @@ class AccessTest extends TestCase
|
|||||||
$this->assertEquals('Asia/Tehran', $datetime->timezone);
|
$this->assertEquals('Asia/Tehran', $datetime->timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testSetDateTime()
|
public function testSetDateTime()
|
||||||
{
|
{
|
||||||
$datetime = verta()->setDateTime(1397,10,11,10,20,11);
|
$datetime = verta()->setDateTime(1397, 10, 11, 10, 20, 11);
|
||||||
|
|
||||||
$this->assertEquals(1397, $datetime->year);
|
$this->assertEquals(1397, $datetime->year);
|
||||||
$this->assertEquals(10, $datetime->month);
|
$this->assertEquals(10, $datetime->month);
|
||||||
@@ -98,10 +97,9 @@ class AccessTest extends TestCase
|
|||||||
$this->assertEquals(11, $datetime->second);
|
$this->assertEquals(11, $datetime->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testSetDate()
|
public function testSetDate()
|
||||||
{
|
{
|
||||||
$datetime = verta()->setDate(1397,10,11);
|
$datetime = verta()->setDate(1397, 10, 11);
|
||||||
|
|
||||||
$this->assertEquals(1397, $datetime->year);
|
$this->assertEquals(1397, $datetime->year);
|
||||||
$this->assertEquals(10, $datetime->month);
|
$this->assertEquals(10, $datetime->month);
|
||||||
@@ -110,7 +108,7 @@ class AccessTest extends TestCase
|
|||||||
|
|
||||||
public function testSetTime()
|
public function testSetTime()
|
||||||
{
|
{
|
||||||
$datetime = verta()->setTime(10,20,11);
|
$datetime = verta()->setTime(10, 20, 11);
|
||||||
|
|
||||||
$this->assertEquals(10, $datetime->hour);
|
$this->assertEquals(10, $datetime->hour);
|
||||||
$this->assertEquals(20, $datetime->minute);
|
$this->assertEquals(20, $datetime->minute);
|
||||||
@@ -124,6 +122,5 @@ class AccessTest extends TestCase
|
|||||||
$this->assertEquals(10, $datetime->hour);
|
$this->assertEquals(10, $datetime->hour);
|
||||||
$this->assertEquals(20, $datetime->minute);
|
$this->assertEquals(20, $datetime->minute);
|
||||||
$this->assertEquals(11, $datetime->second);
|
$this->assertEquals(11, $datetime->second);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,13 +190,13 @@ class ComparisionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$datetime = Verta::parse('1398-10-10 21:30:50');
|
$datetime = Verta::parse('1398-10-10 21:30:50');
|
||||||
|
|
||||||
$result = $datetime->between(Verta::parse('1398-10-10 21:30:50'), Verta::parse('1398-10-11 21:30:50'));
|
$result = $datetime->between(Verta::parse('1398-10-10 21:30:50'), Verta::parse('1398-10-11 21:30:50'));
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
|
|
||||||
$result = $datetime->between(Verta::parse('1398-10-10 21:30:50'), Verta::parse('1398-10-11 21:30:50'), false);
|
$result = $datetime->between(Verta::parse('1398-10-10 21:30:50'), Verta::parse('1398-10-11 21:30:50'), false);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
|
||||||
$result = $datetime->between(Verta::parse('1398-10-13 21:30:50'), Verta::parse('1398-10-09 21:30:50'));
|
$result = $datetime->between(Verta::parse('1398-10-13 21:30:50'), Verta::parse('1398-10-09 21:30:50'));
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,10 +204,10 @@ class ComparisionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$datetime = Verta::parse('1398-10-10 21:30:50');
|
$datetime = Verta::parse('1398-10-10 21:30:50');
|
||||||
|
|
||||||
$result = $datetime->closest(Verta::parse('1398-10-10 21:30:01'), Verta::parse('1398-10-11 21:30:50'));
|
$result = $datetime->closest(Verta::parse('1398-10-10 21:30:01'), Verta::parse('1398-10-11 21:30:50'));
|
||||||
$this->assertEquals($result, Verta::parse('1398-10-10 21:30:01'));
|
$this->assertEquals($result, Verta::parse('1398-10-10 21:30:01'));
|
||||||
|
|
||||||
$result = $datetime->closest(Verta::parse('1398-11-10 21:30:50'), Verta::parse('1398-10-11 21:30:50'));
|
$result = $datetime->closest(Verta::parse('1398-11-10 21:30:50'), Verta::parse('1398-10-11 21:30:50'));
|
||||||
$this->assertEquals($result, Verta::parse('1398-10-11 21:30:50'));
|
$this->assertEquals($result, Verta::parse('1398-10-11 21:30:50'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-12
@@ -23,7 +23,6 @@ class CreatorTest extends TestCase
|
|||||||
$actual = verta()->getTimestamp();
|
$actual = verta()->getTimestamp();
|
||||||
|
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testYesterday()
|
public function testYesterday()
|
||||||
@@ -60,7 +59,7 @@ class CreatorTest extends TestCase
|
|||||||
$datetime = (string) Verta::instance('2019-01-01 10:20:11');
|
$datetime = (string) Verta::instance('2019-01-01 10:20:11');
|
||||||
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
||||||
|
|
||||||
$app = ['verta' => new Verta];
|
$app = ['verta' => new Verta()];
|
||||||
VertaFacade::setFacadeApplication($app);
|
VertaFacade::setFacadeApplication($app);
|
||||||
|
|
||||||
$datetime = (string) VertaFacade::instance('2019-01-01 10:20:11');
|
$datetime = (string) VertaFacade::instance('2019-01-01 10:20:11');
|
||||||
@@ -84,14 +83,14 @@ class CreatorTest extends TestCase
|
|||||||
|
|
||||||
public function testParseFormat()
|
public function testParseFormat()
|
||||||
{
|
{
|
||||||
$datetime = Verta::parseFormat('Y-m-d H:i:s','1397-10-11 10:20:11')->formatGregorian('Y-m-d H:i:s');
|
$datetime = Verta::parseFormat('Y-m-d H:i:s', '1397-10-11 10:20:11')->formatGregorian('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals('2019-01-01 10:20:11', $datetime);
|
$this->assertEquals('2019-01-01 10:20:11', $datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
$datetime = Verta::create(2019,1,1,10,20,11)->format('Y-m-d H:i:s');
|
$datetime = Verta::create(2019, 1, 1, 10, 20, 11)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
||||||
}
|
}
|
||||||
@@ -99,7 +98,7 @@ class CreatorTest extends TestCase
|
|||||||
public function testCreateDate()
|
public function testCreateDate()
|
||||||
{
|
{
|
||||||
$time = (new DateTime())->format("H:i:s");
|
$time = (new DateTime())->format("H:i:s");
|
||||||
$datetime = Verta::createDate(2019,1,1)->format('Y-m-d H:i:s');
|
$datetime = Verta::createDate(2019, 1, 1)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals("1397-10-11 {$time}", $datetime);
|
$this->assertEquals("1397-10-11 {$time}", $datetime);
|
||||||
}
|
}
|
||||||
@@ -107,7 +106,7 @@ class CreatorTest extends TestCase
|
|||||||
public function testCreateTime()
|
public function testCreateTime()
|
||||||
{
|
{
|
||||||
$date = (new DateTime())->format("Y-m-d");
|
$date = (new DateTime())->format("Y-m-d");
|
||||||
$datetime = Verta::createTime(15,19,51)->formatGregorian('Y-m-d H:i:s');
|
$datetime = Verta::createTime(15, 19, 51)->formatGregorian('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals("{$date} 15:19:51", $datetime);
|
$this->assertEquals("{$date} 15:19:51", $datetime);
|
||||||
}
|
}
|
||||||
@@ -121,7 +120,7 @@ class CreatorTest extends TestCase
|
|||||||
|
|
||||||
public function testCreateGregorian()
|
public function testCreateGregorian()
|
||||||
{
|
{
|
||||||
$datetime = Verta::create(2019,1,1,10,20,11)->format('Y-m-d H:i:s');
|
$datetime = Verta::create(2019, 1, 1, 10, 20, 11)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
||||||
}
|
}
|
||||||
@@ -129,7 +128,7 @@ class CreatorTest extends TestCase
|
|||||||
public function testCreateGregorianDate()
|
public function testCreateGregorianDate()
|
||||||
{
|
{
|
||||||
$time = (new DateTime())->format("H:i:s");
|
$time = (new DateTime())->format("H:i:s");
|
||||||
$datetime = Verta::createGregorianDate(2019,1,1)->format('Y-m-d H:i:s');
|
$datetime = Verta::createGregorianDate(2019, 1, 1)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals("1397-10-11 {$time}", $datetime);
|
$this->assertEquals("1397-10-11 {$time}", $datetime);
|
||||||
}
|
}
|
||||||
@@ -137,14 +136,14 @@ class CreatorTest extends TestCase
|
|||||||
public function testCreateGregorianTime()
|
public function testCreateGregorianTime()
|
||||||
{
|
{
|
||||||
$date = (new DateTime())->format("Y-m-d");
|
$date = (new DateTime())->format("Y-m-d");
|
||||||
$datetime = Verta::createGregorianTime(15,19,51)->formatGregorian('Y-m-d H:i:s');
|
$datetime = Verta::createGregorianTime(15, 19, 51)->formatGregorian('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals("{$date} 15:19:51", $datetime);
|
$this->assertEquals("{$date} 15:19:51", $datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateJalali()
|
public function testCreateJalali()
|
||||||
{
|
{
|
||||||
$datetime = Verta::createJalali(1397,10,11,10,20,11)->format('Y-m-d H:i:s');
|
$datetime = Verta::createJalali(1397, 10, 11, 10, 20, 11)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
$this->assertEquals('1397-10-11 10:20:11', $datetime);
|
||||||
}
|
}
|
||||||
@@ -152,7 +151,7 @@ class CreatorTest extends TestCase
|
|||||||
public function testCreateJalaliDate()
|
public function testCreateJalaliDate()
|
||||||
{
|
{
|
||||||
$time = (new DateTime())->format("H:i:s");
|
$time = (new DateTime())->format("H:i:s");
|
||||||
$datetime = Verta::createJalaliDate(1397,10,11)->format('Y-m-d H:i:s');
|
$datetime = Verta::createJalaliDate(1397, 10, 11)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals("1397-10-11 {$time}", $datetime);
|
$this->assertEquals("1397-10-11 {$time}", $datetime);
|
||||||
}
|
}
|
||||||
@@ -160,7 +159,7 @@ class CreatorTest extends TestCase
|
|||||||
public function testCreateJalaliTime()
|
public function testCreateJalaliTime()
|
||||||
{
|
{
|
||||||
$date = verta()->format("Y-m-d");
|
$date = verta()->format("Y-m-d");
|
||||||
$datetime = Verta::createJalaliTime(15,19,51)->format('Y-m-d H:i:s');
|
$datetime = Verta::createJalaliTime(15, 19, 51)->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$this->assertEquals("{$date} 15:19:51", $datetime);
|
$this->assertEquals("{$date} 15:19:51", $datetime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Hekmatinasser\Verta\Tests;
|
namespace Hekmatinasser\Verta\Tests;
|
||||||
|
|
||||||
use DateTime;
|
|
||||||
use Hekmatinasser\Verta\Verta;
|
use Hekmatinasser\Verta\Verta;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ class FormatTest extends TestCase
|
|||||||
$datetime = (string) Verta::parse('1398-10-10 22:30:50');
|
$datetime = (string) Verta::parse('1398-10-10 22:30:50');
|
||||||
|
|
||||||
$this->assertEquals('1398-10-10 22:30:50', $datetime);
|
$this->assertEquals('1398-10-10 22:30:50', $datetime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFormat()
|
public function testFormat()
|
||||||
@@ -111,7 +109,6 @@ class FormatTest extends TestCase
|
|||||||
$difference = $target->formatDifference($datetime);
|
$difference = $target->formatDifference($datetime);
|
||||||
|
|
||||||
$this->assertEquals('1 سال بعد', $difference);
|
$this->assertEquals('1 سال بعد', $difference);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFormatWord()
|
public function testFormatWord()
|
||||||
|
|||||||
@@ -222,6 +222,4 @@ class ModificationTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals('1398-12-29 23:59:59', $result);
|
$this->assertEquals('1398-12-29 23:59:59', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user