migrate to 8

This commit is contained in:
nasser committed 2022-07-03 20:26:41 +04:30
1 parent c1f61c5db3
commit f4cbf76e52
32 files changed
+417 -5141

No files matched your search

-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'0' => '۰',
'1' => '۱',
'2' => '۲',
'3' => '۳',
'4' => '٤',
'5' => '٥',
'6' => '٦',
'7' => '۷',
'8' => '۸',
'9' => '۹',
],
'year_months' => [
'1' => 'حَمَل',
'2' => 'ثَور',
'3' => 'جَوزا',
'4' => 'سَرَطان',
'5' => 'اَسَد',
'6' => 'سُنبُله',
'7' => 'میزان',
'8' => 'عَقرَب',
'9' => 'قَوس',
'10' => 'جَدْی',
'11' => 'دَلو',
'12' => 'حوت',
],
'weekdays' => [
'1' => 'السبت',
'2' => 'الأحد',
'3' => 'الاثنين',
'4' => 'يوم الثلاثاء',
'5' => 'الأربعاء',
'6' => 'يوم الخميس',
'7' => 'جمعة',
],
'date_units' => [
'second' => 'ثواني',
'mintue' => 'الدقائق',
'hour' => 'الساعة',
'day' => 'يوم',
'week' => 'أسبوع',
'month' => 'شهر',
'yaer' => 'سنة',
'decade' => 'عشر سنوات',
'century' => 'مئة عام',
],
'phrase' => [
'am' => 'ق ظ',
'pm' => 'ب ظ',
'ante_meridiem' => 'صباحي',
'post_meridiem' => 'بعد الظهر',
'th' => '',
'ago' => 'قبل',
'now' => 'الآن',
'later' => 'التالي',
],
'validation' => [
'jdate' => ':attribute x ليس تاريخ جلالي صالحًا',
'jdate_equal' => ':attribute لا يساوي تاريخ جلالي :date',
'jdate_not_equal' => 'ال :attribute لا يساوي تاريخ جلالي :date',
'jdatetime' => ':attribute غير صالح لتاريخ جلالي',
'jdatetime_equal' => ':attribute ليس مساويًا لـ تاريخ جلالي :date',
'jdatetime_not_equal' => ':attribute لا يساوي تاريخ جلالي :date',
'jdate_after' => 'يجب أن يكون :attribute تاريخ جلالي بعد :date.',
'jdate_after_equal' => 'يجب أن يكون :attribute هو تاريخ جلالي بعد :date أو يساوي.',
'jdatetime_after' => 'يجب أن يكون :attribute عبارة عن تاريخ جلالي بعد :date.',
'jdatetime_after_equal' => 'يجب أن يكون :attribute عبارة عن تاريخ جلالي بعد :date أو يساوي.',
'jdate_before' => 'يجب أن يكون :attribute تاريخ جلالي قبل :date.',
'jdate_before_equal' => 'يجب أن يكون :attribute تاريخ جلالي قبل :date أو يساوي.',
'jdatetime_before' => 'يجب أن يكون :attribute هو تاريخ جلالي قبل :date.',
'jdatetime_before_equal' => 'يجب أن يكون :attribute هو تاريخ جلالي قبل أو يساوي :date.',
],
'quarters' => [
'1' => 'ربيع',
'2' => 'الصيف',
'3' => 'الخريف',
'4' => 'شتاء',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'0' => '۰',
'1' => '۱',
'2' => '۲',
'3' => '۳',
'4' => '۴',
'5' => '۵',
'6' => '۶',
'7' => '۷',
'8' => '۸',
'9' => '۹',
],
'year_months' => [
'1' => 'آغلارگولر',
'2' => 'گولن',
'3' => 'قیزاران',
'4' => 'قورا پیشیرن',
'5' => 'قویروق دوغان',
'6' => 'زومار',
'7' => 'خزل',
'8' => 'قیروو',
'9' => 'آذر',
'10' => 'چیلله',
'11' => 'دوندوران',
'12' => 'بایرام',
],
'weekdays' => [
'1' => 'شنبه',
'2' => 'یکشنبه',
'3' => 'دوشنبه',
'4' => 'سه شنبه',
'5' => 'چهارشنبه',
'6' => 'پنج شنبه',
'7' => 'جمعه',
],
'date_units' => [
'second' => 'ثانیه',
'mintue' => 'دقیقه',
'hour' => 'ساعت',
'day' => 'روز',
'week' => 'هفته',
'month' => 'ماه',
'yaer' => 'سال',
'decade' => 'دهه',
'century' => 'قرن',
],
'phrase' => [
'am' => 'ق ظ',
'pm' => 'ب ظ',
'ante_meridiem' => 'قبل از ظهر',
'post_meridiem' => 'بعد از ظهر',
'th' => 'ام',
'ago' => 'قبل',
'now' => 'الان',
'later' => 'بعد',
],
'validation' => [
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.',
'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.',
'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.',
'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.',
'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.',
'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.',
'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
],
'quarters' => [
'1' => 'بهار',
'2' => 'تابستان',
'3' => 'پاییز',
'4' => 'زمستان',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'0' => '0',
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
],
'year_months' => [
'1' => 'farvardin',
'2' => 'ordibehesht',
'3' => 'khordad',
'4' => 'tir',
'5' => 'mordad',
'6' => 'shahrivar',
'7' => 'mehr',
'8' => 'aban',
'9' => 'azar',
'10' => 'dey',
'11' => 'bahman',
'12' => 'esfand',
],
'weekdays' => [
'1' => 'saturday',
'2' => 'sunday',
'3' => 'monday',
'4' => 'tuesday',
'5' => 'wednesday',
'6' => 'thursday',
'7' => 'friday',
],
'date_units' => [
'second' => 'second',
'mintue' => 'mintue',
'hour' => 'hour',
'day' => 'day',
'week' => 'week',
'month' => 'month',
'yaer' => 'yaer',
'decade' => 'decade',
'century' => 'century',
],
'phrase' => [
'am' => 'am',
'pm' => 'pm',
'ante_meridiem' => 'ante meridiem',
'post_meridiem' => 'post meridiem',
'th' => 'th',
'ago' => 'ago',
'now' => 'now',
'later' => 'later',
],
'validation' => [
'jdate' => 'The :attribute is not valid Jalali date',
'jdate_equal' => 'The :attribute is not equal Jalali date :date',
'jdate_not_equal' => 'The :attribute is\'nt not equal Jalali date :date',
'jdatetime' => 'The :attribute is not valid Jalali datetime',
'jdatetime_equal' => 'The :attribute is not equal Jalali datetime :date',
'jdatetime_not_equal' => 'The :attribute is\'nt not equal Jalali datetime :date',
'jdate_after' => 'The :attribute must be a Jalali date after :date.',
'jdate_after_equal' => 'The :attribute must be a Jalali date after or equal :date.',
'jdatetime_after' => 'The :attribute must be a Jalali datetime after :date.',
'jdatetime_after_equal' => 'The :attribute must be a Jalali datetime after or equal :date.',
'jdate_before' => 'The :attribute must be a Jalali date before :date.',
'jdate_before_equal' => 'The :attribute must be a Jalali date before or equal :date.',
'jdatetime_before' => 'The :attribute must be a Jalali datetime before :date.',
'jdatetime_before_equal' => 'The :attribute must be a Jalali datetime before or equal :date.',
],
'quarters' => [
'1' => 'spring',
'2' => 'summer',
'3' => 'autumn',
'4' => 'winter',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'0' => '۰',
'1' => '۱',
'2' => '۲',
'3' => '۳',
'4' => '۴',
'5' => '۵',
'6' => '۶',
'7' => '۷',
'8' => '۸',
'9' => '۹',
],
'year_months' => [
'1' => 'فروردین',
'2' => 'اردیبهشت',
'3' => 'خرداد',
'4' => 'تیر',
'5' => 'مرداد',
'6' => 'شهریور',
'7' => 'مهر',
'8' => 'آبان',
'9' => 'آذر',
'10' => 'دی',
'11' => 'بهمن',
'12' => 'اسفند',
],
'weekdays' => [
'1' => 'شنبه',
'2' => 'یکشنبه',
'3' => 'دوشنبه',
'4' => 'سه شنبه',
'5' => 'چهارشنبه',
'6' => 'پنج شنبه',
'7' => 'جمعه',
],
'date_units' => [
'second' => 'ثانیه',
'mintue' => 'دقیقه',
'hour' => 'ساعت',
'day' => 'روز',
'week' => 'هفته',
'month' => 'ماه',
'yaer' => 'سال',
'decade' => 'دهه',
'century' => 'قرن',
],
'phrase' => [
'am' => 'ق ظ',
'pm' => 'ب ظ',
'ante_meridiem' => 'قبل از ظهر',
'post_meridiem' => 'بعد از ظهر',
'th' => 'ام',
'ago' => 'قبل',
'now' => 'الان',
'later' => 'بعد',
],
'validation' => [
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.',
'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.',
'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.',
'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.',
'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.',
'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.',
'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
],
'quarters' => [
'1' => 'بهار',
'2' => 'تابستان',
'3' => 'پاییز',
'4' => 'زمستان',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'0' => '۰',
'1' => '۱',
'2' => '۲',
'3' => '۳',
'4' => '۴',
'5' => '۵',
'6' => '۶',
'7' => '۷',
'8' => '۸',
'9' => '۹',
],
'year_months' => [
'1' => 'اورال',
'2' => 'اید',
'3' => 'بررید',
'4' => 'سرتایستو',
'5' => 'چیله تایستو',
'6' => 'آخیر تایستو',
'7' => 'تخم ریز',
'8' => 'برگ ریز',
'9' => 'چیله زمستو',
'10' => 'بامو',
'11' => 'سیاه بار',
'12' => 'نجیر',
],
'weekdays' => [
'1' => 'شنبه',
'2' => 'یکشنبه',
'3' => 'دوشنبه',
'4' => 'سه شنبه',
'5' => 'چهارشنبه',
'6' => 'پنج شنبه',
'7' => 'جمعه',
],
'date_units' => [
'second' => 'ثانیه',
'mintue' => 'دقیقه',
'hour' => 'ساعت',
'day' => 'روز',
'week' => 'هفته',
'month' => 'ماه',
'yaer' => 'سال',
'decade' => 'دهه',
'century' => 'قرن',
],
'phrase' => [
'am' => 'ق ظ',
'pm' => 'ب ظ',
'ante_meridiem' => 'قبل از ظهر',
'post_meridiem' => 'بعد از ظهر',
'th' => 'ام',
'ago' => 'قبل',
'now' => 'الان',
'later' => 'بعد',
],
'validation' => [
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.',
'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.',
'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.',
'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.',
'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.',
'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.',
'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
],
'quarters' => [
'1' => 'بهار',
'2' => 'تابستان',
'3' => 'پاییز',
'4' => 'زمستان',
],
];
-82
View File
@@ -1,82 +0,0 @@
<?php
return [
'numbers' => [
'0' => '۰',
'1' => '۱',
'2' => '۲',
'3' => '۳',
'4' => '۴',
'5' => '۵',
'6' => '۶',
'7' => '۷',
'8' => '۸',
'9' => '۹',
],
'year_months' => [
'1' => 'خاکه‌لێوه',
'2' => 'گوڵان',
'3' => 'جۆزەردان',
'4' => 'پووشپەڕ',
'5' => 'گەلاوێژ',
'6' => 'خەرمانان',
'7' => 'ڕەزبەر',
'8' => 'خەزەڵوەر',
'9' => 'سەرماوەز',
'10' => 'بەفرانبار',
'11' => 'ڕێبەندان',
'12' => 'رەشەمە',
],
'weekdays' => [
'1' => 'شه ممه',
'2' => 'یه کشه ممه',
'3' => 'دوو شه ممه',
'4' => 'سی شه ممه',
'5' => 'چوار شه ممه',
'6' => 'په ن شه ممم',
'7' => 'هه ینی',
],
'date_units' => [
'second' => 'ثانیه',
'mintue' => 'دقیقه',
'hour' => 'ساعت',
'day' => 'روز',
'week' => 'هفته',
'month' => 'ماه',
'yaer' => 'سال',
'decade' => 'دهه',
'century' => 'قرن',
],
'phrase' => [
'am' => 'ق ظ',
'pm' => 'ب ظ',
'ante_meridiem' => 'قبل از ظهر',
'post_meridiem' => 'بعد از ظهر',
'th' => 'ام',
'ago' => 'قبل',
'now' => 'الان',
'later' => 'بعد',
],
'validation' => [
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.',
'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.',
'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.',
'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.',
'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.',
'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.',
'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
],
'quarters' => [
'1' => 'بهار',
'2' => 'تابستان',
'3' => 'پاییز',
'4' => 'زمستان',
],
];
-81
View File
@@ -1,81 +0,0 @@
<?php
return [
'numbers' => [
'0' => '۰',
'1' => '۱',
'2' => '۲',
'3' => '۳',
'4' => '۴',
'5' => '۵',
'6' => '۶',
'7' => '۷',
'8' => '۸',
'9' => '۹',
],
'year_months' => [
'1' => 'وری',
'2' => 'غویی',
'3' => 'غبرګولی',
'4' => 'چنګاښ',
'5' => 'زمری',
'6' => 'وږی',
'7' => 'تله',
'8' => 'لړم',
'9' => 'لیندۍ',
'10' => 'مرغومی',
'11' => 'سلواغه',
'12' => 'کب',
],
'weekdays' => [
'1' => 'شنبې',
'2' => 'یکشنبه',
'3' => 'دوشنبه',
'4' => 'سې شنبه',
'5' => 'چهارشنبه',
'6' => 'پنج شنبه',
'7' => 'جمعه',
],
'date_units' => [
'second' => 'ثانیه',
'mintue' => 'دقیقه',
'hour' => 'ساعت',
'day' => 'روز',
'week' => 'هفته',
'month' => 'ماه',
'yaer' => 'سال',
'century' => 'قرن',
],
'phrase' => [
'am' => 'ق ظ',
'pm' => 'ب ظ',
'ante_meridiem' => 'قبل از ظهر',
'post_meridiem' => 'بعد از ظهر',
'th' => 'ام',
'ago' => 'قبل',
'now' => 'الان',
'later' => 'بعد',
],
'validation' => [
'jdate' => ':attribute' . ' تاریخ شمسی معتبر نمی باشد.',
'jdate_equal' => ':attribute' . ' تاریخ شمسی برابر ' . ':date' . ' نمی باشد.',
'jdate_not_equal' => ':attribute' . ' تاریخ شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdatetime' => ':attribute' . ' تاریخ و زمان شمسی معتبر نمی باشد.',
'jdatetime_equal' => ':attribute' . ' تاریخ و زمان شمسی مساوی ' . ':date' . ' نمی باشد.',
'jdatetime_not_equal' => ':attribute' . ' تاریخ و زمان شمسی نامساوی ' . ':date' . ' نمی باشد.',
'jdate_after' => ':attribute' . ' تاریخ شمسی باید بعد از ' . ':date' . ' باشد.',
'jdate_after_equal' => ':attribute' . ' تاریخ شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdatetime_after' => ':attribute' . ' تاریخ و زمان شمسی باید بعد از ' . ':date' . ' باشد.',
'jdatetime_after_equal' => ':attribute' . ' تاریخ و زمان شمسی باید بعد یا برابر از ' . ':date' . ' باشد.',
'jdate_before' => ':attribute' . ' تاریخ شمسی باید قبل از ' . ':date' . ' باشد.',
'jdate_before_equal' => ':attribute' . ' تاریخ شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
'jdatetime_before' => ':attribute' . ' تاریخ و زمان شمسی باید قبل از ' . ':date' . ' باشد.',
'jdatetime_before_equal' => ':attribute' . ' تاریخ و زمان شمسی باید قبل یا برابر از ' . ':date' . ' باشد.',
],
'quarters' => [
'1' => 'بهار',
'2' => 'تابستان',
'3' => 'پاییز',
'4' => 'زمستان',
],
];
-1
View File
@@ -111,7 +111,6 @@ class VertaServiceProvider extends ServiceProvider
foreach ($this->rules as $name => $methods) {
if (array_key_exists('extend', $methods) || array_key_exists('replacer', $methods)) {
Validator::extend($name, $className . $methods['extend']);
Validator::replacer($name, $className . $methods['replacer']);
}
}
-261
View File
@@ -1,261 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use DateTimeZone;
use Hekmatinasser\Verta\Verta;
use InvalidArgumentException;
trait Accessor
{
/**
* Get a part of the Verta object
*
* @param string $name
* @return string|int
*@throws InvalidArgumentException
*/
public function __get($name)
{
static $formats = [
'year' => 'Y',
'month' => 'n',
'day' => 'j',
'hour' => 'G',
'minute' => 'i',
'second' => 's',
'micro' => 'u',
'dayOfWeek' => 'w',
'dayOfYear' => 'z',
'weekOfYear' => 'W',
'daysInMonth' => 't',
'timestamp' => 'U',
];
if (array_key_exists($name, $formats)) {
return (int) $this->format($formats[$name]);
} elseif ($name === 'quarter') {
return (int) ceil($this->month / static::MONTHS_PER_QUARTER);
} elseif ($name === 'timezone') {
return $this->getTimezone()->getName();
}
throw new InvalidArgumentException(sprintf("Unknown getter '%s'", $name));
}
/**
* Check if an attribute exists on the object
*
* @param string $name
* @return bool
*/
public function __isset($name)
{
try {
$this->__get($name);
} catch (InvalidArgumentException $e) {
return false;
}
return true;
}
/**
* Set a part of the Verta object
*
* @param string $name
* @param \DateTimeZone|int|string $value
* @throws \InvalidArgumentException
*/
public function __set($name, $value)
{
switch ($name) {
case 'year':
case 'month':
case 'day':
case 'hour':
case 'minute':
case 'second':
list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-n-j-G-i-s'));
$$name = $value;
$this->setDateTime($year, $month, $day, $hour, $minute, $second);
break;
case 'timestamp':
$this->setTimestamp($value);
break;
case 'timezone':
case 'tz':
$this->setTimezone(new DateTimeZone($value));
break;
default:
throw new InvalidArgumentException(sprintf("Unknown setter '%s'", $name));
}
}
/**
* Set the instance's year
*
* @param int $value
* @return static
*/
public function year($value)
{
$this->year = $value;
return $this;
}
/**
* Set the instance's month
*
* @param int $value
* @return static
*/
public function month($value)
{
$this->month = $value;
return $this;
}
/**
* Set the instance's day
*
* @param int $value
* @return static
*/
public function day($value)
{
$this->day = $value;
return $this;
}
/**
* Set the instance's hour
*
* @param int $value
* @return static
*/
public function hour($value)
{
$this->hour = $value;
return $this;
}
/**
* Set the instance's minute
*
* @param int $value
* @return static
*/
public function minute($value)
{
$this->minute = $value;
return $this;
}
/**
* Set the instance's second
*
* @param int $value
* @return static
*/
public function second($value)
{
$this->second = $value;
return $this;
}
/**
* Set the instance's timestamp
*
* @param int $value
* @return static
*/
public function timestamp($value)
{
return parent::setTimestamp($value);
}
/**
* Alias for setTimezone()
*
* @param \DateTimeZone|string $value
*
* @return static
*/
public function timezone($value)
{
return parent::setTimezone(new DateTimeZone($value));
}
/**
* Set the date and time all together
*
* @param int $year
* @param int $month
* @param int $day
* @param int $hour
* @param int $minute
* @param int $second
* @param int $microseconds
*
* @return Verta
*/
public function setDateTime($year, $month, $day, $hour, $minute, $second = 0, $microseconds = 0)
{
return $this->setDateJalali($year, $month, $day)->setTime($hour, $minute, $second, $microseconds);
}
/**
* Sets the current date of the DateTime object to a different date.
* Calls modify as a workaround for a php bug
*
* @param int $year
* @param int $month
* @param int $day
*
* @return Verta
*/
public function setDateJalali($year, $month, $day): Verta
{
if (static::isValidDate($year, $month, $day)) {
list($year, $month, $day) = self::getGregorian($year, $month, $day);
parent::setDate($year, $month, $day);
}
return $this;
}
/**
* Set the time by time string
*
* @param string $time
* @return Verta
* @throws \InvalidArgumentException
*/
public function setTimeString($time): Verta
{
$time = explode(':', $time);
$hour = $time[0];
$minute = $time[1] ?? 0;
$second = $time[2] ?? 0;
if (static::isValidTime($hour, $minute, $second)) {
parent::setTime($hour, $minute, $second, 0);
}
return $this;
}
}
-160
View File
@@ -1,160 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Boundaries
{
/**
* Resets the time to 00:00:00
*
* @return static
*/
public function startMinute()
{
return $this->setTime($this->hour, $this->minute, 0);
}
/**
* Resets the time to 23:59:59
*
* @return static
*/
public function endMinute()
{
return $this->setTime($this->hour, $this->minute, 59);
}
/**
* Resets the time to 00:00:00
*
* @return static
*/
public function startHour()
{
return $this->setTime($this->hour, 0, 0);
}
/**
* Resets the time to 23:59:59
*
* @return static
*/
public function endHour()
{
return $this->setTime($this->hour, 59, 59);
}
/**
* Resets the time to 00:00:00
*
* @return static
*/
public function startDay()
{
return $this->setTime(0, 0, 0);
}
/**
* Resets the time to 23:59:59
*
* @return static
*/
public function endDay()
{
return $this->setTime(23, 59, 59);
}
/**
* Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
*
* @return static
*/
public function startWeek()
{
while ($this->dayOfWeek !== static::$weekStartsAt) {
$this->subDay();
}
return $this->startDay();
}
/**
* Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
*
* @return static
*/
public function endWeek()
{
while ($this->dayOfWeek !== static::$weekEndsAt) {
$this->addDay();
}
return $this->endDay();
}
/**
* Resets the date to the first day of the month and the time to 00:00:00
*
* @return static
*/
public function startMonth()
{
return $this->setDateTime($this->year, $this->month, 1, 0, 0, 0);
}
/**
* Resets the date to end of the month and time to 23:59:59
*
* @return static
*/
public function endMonth()
{
return $this->setDateTime($this->year, $this->month, $this->daysInMonth, 23, 59, 59);
}
/**
* Resets the date to the first day of the quarter and the time to 00:00:00
*
* @return static
*/
public function startQuarter()
{
$month = ($this->quarter - 1) * static::MONTHS_PER_QUARTER + 1;
return $this->setDateTime($this->year, $month, 1, 0, 0, 0);
}
/**
* Resets the date to end of the quarter and time to 23:59:59
*
* @return static
*/
public function endQuarter()
{
$month = $this->quarter * static::MONTHS_PER_QUARTER;
return $this->setDateJalali($this->year, $month, 1)->endMonth();
}
/**
* Resets the date to the first day of the year and the time to 00:00:00
*
* @return static
*/
public function startYear()
{
return $this->setDateTime($this->year, 1, 1, 0, 0, 0);
}
/**
* Resets the date to end of the year and time to 23:59:59
*
* @return static
*/
public function endYear()
{
$day = $this->format('L') ? 30 : 29;
return $this->setDateTime($this->year, 12, $day, 23, 59, 59);
}
}
-607
View File
@@ -1,607 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Verta\Verta;
trait Comparison
{
/**
* check jalali the instance is a leap year
*
* @param int $year
* @return bool
*/
public static function isLeapYear($year)
{
return in_array(($year % 33), [1 , 5 , 9 , 13 ,17 , 22 , 26 , 30]);
}
/**
* validate a jalali date (jalali equivalent of php checkdate() function)
*
* @param int $month
* @param int $day
* @param int $year
* @return bool
*/
public static function isValidDate($year, $month, $day)
{
if ($year < 0 || $year > 32766) {
return false;
}
if ($month < 1 || $month > 12) {
return false;
}
$dayLastMonthJalali = static::isLeapYear($year) && ($month == 12) ? 30 : static::$daysMonthJalali[intval($month) - 1];
if ($day < 1 || $day > $dayLastMonthJalali) {
return false;
}
return true;
}
/**
* validate a time
*
* @param int $hour
* @param int $minute
* @param int $second
* @return bool
*/
public static function isValidTime($hour, $minute, $second)
{
return $hour >= 0 && $hour <= 23
&& $minute >= 0 && $minute <= 59
&& $second >= 0 && $second <= 59;
}
/**
* Determines if the instance is equal to another
*
* @param Verta $v
*
* @return bool
*/
public function eq(Verta $v = null)
{
return $this == ($v ?: new static());
}
/**
* Determines if the instance is equal to another
*
* @param Verta $v
*
* @see eq()
*
* @return bool
*/
public function equalTo(Verta $v = null)
{
return $this->eq($v);
}
/**
* Determines if the instance is not equal to another
*
* @param Verta $v
*
* @return bool
*/
public function ne(Verta $v = null)
{
return ! $this->eq($v);
}
/**
* Determines if the instance is not equal to another
*
* @param Verta $v
*
* @see ne()
*
* @return bool
*/
public function notEqualTo(Verta $v = null)
{
return $this->ne($v);
}
/**
* Determines if the instance is greater (after) than another
*
* @param Verta $v
*
* @return bool
*/
public function gt(Verta $v = null)
{
return $this > ($v ?: new static());
}
/**
* Determines if the instance is greater (after) than another
*
* @param Verta $v
*
* @see gt()
*
* @return bool
*/
public function greaterThan(Verta $v = null)
{
return $this->gt($v);
}
/**
* Determines if the instance is greater (after) than or equal to another
*
* @param Verta $v
*
* @return bool
*/
public function gte(Verta $v = null)
{
return $this >= ($v ?: new static());
}
/**
* Determines if the instance is greater (after) than or equal to another
*
* @param Verta $v
*
* @see gte()
*
* @return bool
*/
public function greaterThanOrEqualTo(Verta $v = null)
{
return $this->gte($v);
}
/**
* Determines if the instance is less (before) than another
*
* @param Verta $v
*
* @return bool
*/
public function lt(Verta $v = null)
{
return $this < ($v ?: new static());
}
/**
* Determines if the instance is less (before) than another
*
* @param Verta $v
*
* @see lt()
*
* @return bool
*/
public function lessThan(Verta $v = null)
{
return $this->lt($v);
}
/**
* Determines if the instance is less (before) or equal to another
*
* @param Verta $v
*
* @return bool
*/
public function lte(Verta $v = null)
{
return $this <= ($v ?: new static());
}
/**
* Determines if the instance is less (before) or equal to another
*
* @param Verta $v
*
* @see lte()
*
* @return bool
*/
public function lessThanOrEqualTo(Verta $v = null)
{
return $this->lte($v);
}
/**
* Determines if the instance is between two others
*
* @param Verta $v1
* @param Verta $v2
* @param bool $equal Indicates if a > and < comparison should be used or <= or >=
*
* @return bool
*/
public function between(Verta $v1, Verta $v2, $equal = true)
{
if ($v1->gt($v2)) {
$temp = $v1;
$v1 = $v2;
$v2 = $temp;
}
if ($equal) {
return $this->gte($v1) && $this->lte($v2);
}
return $this->gt($v1) && $this->lt($v2);
}
/**
* Get the closest date from the instance.
*
* @param Verta $v1
* @param Verta $v2
*
* @return static
*/
public function closest(Verta $v1, Verta $v2)
{
return $this->diffSeconds($v1) < $this->diffSeconds($v2) ? $v1 : $v2;
}
/**
* Get the farthest date from the instance.
*
* @param Verta $v1
* @param Verta $v2
*
* @return static
*/
public function farthest(Verta $v1, Verta $v2)
{
return $this->diffSeconds($v1) > $this->diffSeconds($v2) ? $v1 : $v2;
}
/**
* Get the minimum instance between a given instance (default now) and the current instance.
*
* @param Verta|null $v
*
* @return static
*/
public function min(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->lt($v) ? $this : $v;
}
/**
* Get the minimum instance between a given instance (default now) and the current instance.
*
* @param Verta|null $v
*
* @see min()
*
* @return static
*/
public function minimum(Verta $v = null)
{
return $this->min($v);
}
/**
* Get the maximum instance between a given instance (default now) and the current instance.
*
* @param Verta|null $v
*
* @return static
*/
public function max(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->gt($v) ? $this : $v;
}
/**
* Get the maximum instance between a given instance (default now) and the current instance.
*
* @param Verta|null $v
*
* @see max()
*
* @return static
*/
public function maximum(Verta $v = null)
{
return $this->max($v);
}
/**
* Determines if the instance is a weekday
*
* @return bool
*/
public function isWeekday()
{
return ! $this->isWeekend();
}
/**
* Determines if the instance is a weekend day
*
* @return bool
*/
public function isWeekend()
{
return in_array($this->dayOfWeek, static::$weekendDays);
}
/**
* Determines if the instance is yesterday
*
* @return bool
*/
public function isYesterday()
{
return $this->formatDate() === static::yesterday($this->getTimezone())->formatDate();
}
/**
* Determines if the instance is today
*
* @return bool
*/
public function isToday()
{
return $this->formatDate() === static::now($this->getTimezone())->formatDate();
}
/**
* Determines if the instance is tomorrow
*
* @return bool
*/
public function isTomorrow()
{
return $this->formatDate() === static::tomorrow($this->getTimezone())->formatDate();
}
/**
* Determines if the instance is within the next week
*
* @return bool
*/
public function isNextWeek(): bool
{
return $this->weekOfYear === static::now($this->getTimezone())->addWeek()->weekOfYear;
}
/**
* Determines if the instance is within the last week
*
* @return bool
*/
public function isLastWeek()
{
return $this->weekOfYear === static::now($this->getTimezone())->subWeek()->weekOfYear;
}
/**
* Determines if the instance is within the next month
*
* @return bool
*/
public function isNextMonth()
{
return $this->format('Y-m') === static::now($this->getTimezone())->addMonth()->format('Y-m');
}
/**
* Determines if the instance is within the last month
*
* @return bool
*/
public function isLastMonth()
{
return $this->format('Y-m') === static::now($this->getTimezone())->subMonth()->format('Y-m');
}
/**
* Determines if the instance is within next year
*
* @return bool
*/
public function isNextYear()
{
return $this->year === static::now($this->getTimezone())->addYear()->year;
}
/**
* Determines if the instance is within the previous year
*
* @return bool
*/
public function isLastYear()
{
return $this->year === static::now($this->getTimezone())->subYear()->year;
}
/**
* Determines if the instance is in the future, ie. greater (after) than now
*
* @return bool
*/
public function isFuture()
{
return $this->gt(static::now($this->getTimezone()));
}
/**
* Determines if the instance is in the past, ie. less (before) than now
*
* @return bool
*/
public function isPast()
{
return $this->lt(static::now($this->getTimezone()));
}
/**
* Compares the formatted values of the two dates.
*
* @param string $format The date formats to compare.
* @param Verta|null $v The instance to compare with or null to use current day.
*
* @return bool
*/
public function isSameAs($format, Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->format($format) === $v->format($format);
}
/**
* Determines if the instance is in the current year
*
* @return bool
*/
public function isCurrentYear()
{
return $this->isSameYear();
}
/**
* Checks if the passed in date is in the same year as the instance year.
*
* @param Verta|null $v The instance to compare with or null to use current day.
*
* @return bool
*/
public function isSameYear(Verta $v = null)
{
return $this->isSameAs('Y', $v);
}
/**
* Determines if the instance is in the current month
*
* @return bool
*/
public function isCurrentMonth()
{
return $this->isSameMonth();
}
/**
* Checks if the passed in date is in the same month as the instance month (and year if needed).
* $this->assertFalse($datetime->isCurrentMonth());
* @param Verta|null $v The instance to compare with or null to use current day.
* @param bool $ofSameYear Check if it is the same month in the same year.
*
* @return bool
*/
public function isSameMonth(Verta $v = null, $ofSameYear = false)
{
$format = $ofSameYear ? 'Y-m' : 'm';
return $this->isSameAs($format, $v);
}
/**
* Checks if the passed in date is the same day as the instance current day.
*
* @param Verta $v
*
* @return bool
*/
public function isSameDay(Verta $v)
{
return $this->formatDate() === $v->formatDate();
}
/**
* Check if its the birthday. Compares the date/month values of the two dates.
*
* @param Verta|null $dt The instance to compare with or null to use current day.
*
* @return bool
*/
public function isBirthday(Verta $v = null)
{
return $this->isSameAs('md', $v);
}
/**
* Checks if this day is a Saturday.
*
* @return bool
*/
public function isSaturday()
{
return $this->dayOfWeek === static::SATURDAY;
}
/**
* Checks if this day is a Sunday.
*
* @return bool
*/
public function isSunday()
{
return $this->dayOfWeek === static::SUNDAY;
}
/**
* Checks if this day is a Monday.
*
* @return bool
*/
public function isMonday()
{
return $this->dayOfWeek === static::MONDAY;
}
/**
* Checks if this day is a Tuesday.
*
* @return bool
*/
public function isTuesday()
{
return $this->dayOfWeek === static::TUESDAY;
}
/**
* Checks if this day is a Wednesday.
*
* @return bool
*/
public function isWednesday()
{
return $this->dayOfWeek === static::WEDNESDAY;
}
/**
* Checks if this day is a Thursday.
*
* @return bool
*/
public function isThursday()
{
return $this->dayOfWeek === static::THURSDAY;
}
/**
* Checks if this day is a Friday.
*
* @return bool
*/
public function isFriday()
{
return $this->dayOfWeek === static::FRIDAY;
}
}
-421
View File
@@ -1,421 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use DateTime;
use DateTimeZone;
use Exception;
use Illuminate\Support\Carbon;
use InvalidArgumentException;
trait Creator
{
/**
* create object of Jalali
*
* @param DateTime|string|int|null $datetime [optional]
* @param DateTimeZone|string|null $timezone [optional]
* @internal param timestamp $timestamp [optional]
*/
public function __construct($datetime = null, $timezone = null)
{
$dt = $datetime;
if (empty($datetime)) {
$dt = 'now';
} elseif (is_string($datetime)) {
$dt = self::faToEnNumbers(self::arToEnNumbers($datetime));
} elseif ($datetime instanceof DateTime) {
$dt = "@{$datetime->getTimestamp()}";
} elseif (is_int($datetime)) {
$dt = "@$datetime";
}
try {
if ($datetime instanceof DateTime) {
parent::__construct($dt);
parent::setTimezone($datetime->getTimezone());
} else {
parent::__construct($dt, static::createTimeZone($timezone));
}
self::loadMessages();
} catch (Exception $exception) {
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
}
}
/**
* Create a Verta now datetime
*
*
* @param null $timezone
* @return static
*/
public static function now($timezone = null)
{
return new static(null, $timezone);
}
/**
* Create a Verta instance for today.
*
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function today($timezone = null)
{
return (new static(null, $timezone))->startDay();
}
/**
* Create a Verta instance for tomorrow.
*
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function tomorrow($timezone = null)
{
return (new static(null, $timezone))->addDay()->startDay();
}
/**
* Create a Verta instance for yesterday.
*
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function yesterday($timezone = null)
{
return (new static(null, $timezone))->subDay()->startDay();
}
/**
* Create a Verta instance from a DateTime one
*
* @param $datetime [optional]
* @param \DateTimeZone|string|null $timezone [optional]
*
* @return static
*/
public static function instance($datetime = null, $timezone = null)
{
return new static($datetime, $timezone);
}
/**
* Get a copy of the instance.
*
* @return static
*/
public function copy()
{
return clone $this;
}
/**
* Get a copy of the instance.
*
* @return static
*/
public function clone()
{
return clone $this;
}
/**
* Create a DateTime instance from Verta
*
* @return datetime $datetime
*/
public function datetime()
{
$dt = new DateTime(date('Y-m-d H:i:s', $this->getTimestamp()));
$dt->setTimezone($this->getTimezone());
return $dt;
}
/**
* Create a Carbon instance from Verta
*
* @return Carbon
*/
public function toCarbon()
{
return Carbon::instance($this->datetime());
}
/**
* Create a Verta instance from a DateTime one
*
* @param $datetime [optional]
* @param bool $timezone [optional]
*
* @return static
*/
public static function parse($datetime, $timezone = null)
{
self::loadMessages();
$names = array_map(function ($value) {
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(array_values(self::$messages['year_months']), range(1, 12), $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'])) {
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
}
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
list($hour, $minute, $second) = [$parse['hour'], $parse['minute'], $parse['second']];
$datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second);
return new static($datetime, $timezone);
}
/**
* Create a Verta instance from a DateTime one
*
* @param string $format
* @param string $datetime [optional]
* @param bool $timezone [optional]
* @return static
*/
public static function parseFormat($format, $datetime, $timezone = null)
{
self::loadMessages();
$formatted = str_replace(array_values(self::$messages['year_months']), range(1, 12), $datetime);
$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'])) {
throw new InvalidArgumentException(sprintf("Unknown datetime '%s'", $datetime));
}
list($year, $month, $day) = self::getGregorian($parse['year'], $parse['month'], $parse['day']);
list($hour, $minute, $second) = [$parse['hour'], $parse['minute'], $parse['second']];
$datetime = sprintf('%04s-%02s-%02s %02s:%02s:%02s', $year, $month, $day, $hour, $minute, $second);
return new static($datetime, $timezone);
}
/**
* Create a new Verta instance from a specific date and time gregorain.
*
* If any of feild are set to null their now() values will
* be used.
*
* @param int|null $year
* @param int|null $month
* @param int|null $day
* @param int|null $hour
* @param int|null $minute
* @param int|null $second
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createGregorian($year, $month, $day, $hour, $minute, $second, $timezone);
}
/**
* Create a Verta from just a date gregorian.
*
* @param int|null $year
* @param int|null $month
* @param int|null $day
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function createDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::create($year, $month, $day, null, null, null, $timezone);
}
/**
* Create a Verta instance from just a time gregorian.
*
* @param int|null $hour
* @param int|null $minute
* @param int|null $second
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function createTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::create(null, null, null, $hour, $minute, $second, $timezone);
}
/**
* Create a Verta instance from a timestamp.
*
* @param int $timestamp
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function createTimestamp($timestamp, $timezone = null)
{
return static::instance($timestamp, $timezone);
}
/**
* @param null $timezone
* @return DateTimeZone|string|null
*/
protected static function createTimeZone($timezone = null)
{
if ($timezone === null) {
return new DateTimeZone(date_default_timezone_get());
} elseif ($timezone instanceof DateTimeZone) {
return $timezone;
} else {
$tz = @timezone_open(strval($timezone));
if ($tz === false) {
throw new InvalidArgumentException(sprintf("Unknown timezone '%s'", $tz));
}
return $tz;
}
}
/**
* Create a new Verta instance from a specific date and time gregorain.
*
* If any of feild are set to null their now() values will
* be used.
*
* @param int|null $year
* @param int|null $month
* @param int|null $day
* @param int|null $hour
* @param int|null $minute
* @param int|null $second
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
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');
$defaults = array_combine(['year', 'month', 'day', 'hour', 'minute', 'second'], explode('-', $now));
$year = $year ?? intval($defaults['year']);
$month = $month ?? intval($defaults['month']);
$day = $day ?? intval($defaults['day']);
$hour = $hour ?? intval($defaults['hour']);
$minute = $minute ?? intval($defaults['minute']);
$second = $second ?? intval($defaults['second']);
if (! checkdate($month, $day, $year) || ! static::isValidTime($hour, $minute, $second)) {
throw new \InvalidArgumentException('Unknown datetime');
}
return new static(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second), $timezone);
}
/**
* Create a Verta from just a date gregorian.
*
* @param int|null $year
* @param int|null $month
* @param int|null $day
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function createGregorianDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::createGregorian($year, $month, $day, null, null, null, $timezone);
}
/**
* Create a Verta instance from just a time gregorian.
*
* @param int|null $hour
* @param int|null $minute
* @param int|null $second
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function createGregorianTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createGregorian(null, null, null, $hour, $minute, $second, $timezone);
}
/**
* Create a new Verta instance from a specific date and time.
*
* If any of feild are set to null their now() values will
* be used.
*
* @param int|null $year
* @param int|null $month
* @param int|null $day
* @param int|null $hour
* @param int|null $minute
* @param int|null $second
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
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');
$defaults = array_combine(['year', 'month', 'day', 'hour', 'minute', 'second'], explode('-', $now));
$year = $year ?? intval($defaults['year']);
$month = $month ?? intval($defaults['month']);
$day = $day ?? intval($defaults['day']);
$hour = $hour ?? intval($defaults['hour']);
$minute = $minute ?? intval($defaults['minute']);
$second = $second ?? intval($defaults['second']);
if (! static::isValidDate($year, $month, $day) || ! static::isValidTime($hour, $minute, $second)) {
throw new \InvalidArgumentException('Unknown datetime');
}
return static::parse(sprintf('%s-%s-%s %s:%s:%s', $year, $month, $day, $hour, $minute, $second));
}
/**
* Create a Verta from just a date.
*
* @param int|null $year
* @param int|null $month
* @param int|null $day
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function createJalaliDate($year = null, $month = null, $day = null, $timezone = null)
{
return static::createJalali($year, $month, $day, null, null, null, $timezone);
}
/**
* Create a Verta instance from just a time.
*
* @param int|null $hour
* @param int|null $minute
* @param int|null $second
* @param \DateTimeZone|string|null $timezone
*
* @return static
*/
public static function createJalaliTime($hour = null, $minute = null, $second = null, $timezone = null)
{
return static::createJalali(null, null, null, $hour, $minute, $second, $timezone);
}
}
-59
View File
@@ -1,59 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Verta\VertaInterface;
trait Date
{
use Accessor;
use Comparison;
use Creator;
use Formatting;
use Modification;
use Transformation;
use Translator;
use Boundaries;
use Difference;
/**
* Format to use for __toString.
*
* @var string
*/
protected static $stringFormat = VertaInterface::DEFAULT_STRING_FORMAT;
/**
* First day of week.
*
* @var int
*/
protected static $weekStartsAt = VertaInterface::SATURDAY;
/**
* Last day of week.
*
* @var int
*/
protected static $weekEndsAt = VertaInterface::FRIDAY;
/**
* Days of weekend.
*
* @var array
*/
protected static $weekendDays = [VertaInterface::THURSDAY, VertaInterface::FRIDAY];
/**
* number day in months gregorian
*
* @var array
*/
protected static $daysMonthGregorian = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
/**
* number day in month jalali
*
* @var array
*/
protected static $daysMonthJalali = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];
}
-100
View File
@@ -1,100 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Verta\Verta;
trait Difference
{
/**
* Get the difference in years
*
* @param Verta|null $v
*
* @return int
*/
public function diffYears(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return (int) $this->diff($v->datetime())->format('%r%y');
}
/**
* Get the difference in months
*
* @param Verta|null $v
*
* @return int
*/
public function diffMonths(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $this->diffYears($v) * static::MONTHS_PER_YEAR + (int) $this->diff($v->datetime())->format('%r%m');
}
/**
* Get the difference in weeks
*
* @param Verta|null $v
*
* @return int
*/
public function diffWeeks(Verta $v = null)
{
return (int) ($this->diffDays($v) / static::DAYS_PER_WEEK);
}
/**
* Get the difference in days
*
* @param Verta|null $v
*
* @return int
*/
public function diffDays(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return (int) $this->diff($v->datetime())->format('%r%a');
}
/**
* Get the difference in hours
*
* @param Verta|null $v
*
* @return int
*/
public function diffHours(Verta $v = null)
{
return (int) ($this->diffSeconds($v) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR);
}
/**
* Get the difference in minutes
*
* @param Verta|null $v
*
* @return int
*/
public function diffMinutes(Verta $v = null)
{
return (int) ($this->diffSeconds($v) / static::SECONDS_PER_MINUTE);
}
/**
* Get the difference in seconds
*
* @param Verta|null $v
*
* @return int
*/
public function diffSeconds(Verta $v = null)
{
$v = $v ?: static::now($this->getTimezone());
return $v->getTimestamp() - $this->getTimestamp();
}
}
-478
View File
@@ -1,478 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
use Hekmatinasser\Notowo\Notowo;
use Hekmatinasser\Verta\Verta;
use ReturnTypeWillChange;
trait Formatting
{
/**
* Reset the format used to the default when type juggling a Verta instance to a string
*/
public static function resetStringFormat()
{
static::setStringFormat(static::DEFAULT_STRING_FORMAT);
}
/**
* Set the default format used when type juggling a Verta instance to a string
*
* @param string $format
*/
public static function setStringFormat($format)
{
static::$stringFormat = $format;
}
/**
* Format the instance as a string using the set format
*
* @return string
*/
public function __toString()
{
return $this->format(static::$stringFormat);
}
/**
* The format of the outputted date string (jalali equivalent of php date() function)
*
* @param string $format for example 'Y-m-d H:i:s'
* @return string
*/
protected function date(string $format): string
{
$timestamp = $this->getTimestamp();
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w'));
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
$pWeek = $gWeek + 1;
if ($pWeek >= 7) {
$pWeek = 0;
}
$lengh = strlen($format);
$index = 0;
$result = '';
while ($index < $lengh) {
$char = $format[$index];
if ($char == '\\') {
$result .= $format[++$index];
$index++;
continue;
}
$result .= $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
$index++;
}
return $result;
}
/**
* The format of the outputted date charactre (jalali equivalent of php date() function)
*
* @param string $char
* @param int $timestamp
* @param int $pYear
* @param int $pMonth
* @param int $pDay
* @param int $pWeek
* @return string
*/
private function characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek)
{
switch ($char) {
# Day
case 'd':
return sprintf('%02s', $pDay);
case 'D':
return substr(self::$messages['weekdays'][$pWeek + 1], 0, 2);
case 'j':
return $pDay;
case 'l':
return self::$messages['weekdays'][$pWeek + 1];
case 'N':
return $pWeek + 1;
case 'w':
return $pWeek;
case 'z':
return $this->daysYear($pMonth, $pDay);
case 'S':
return static::$messages['phrase']['th'];
# Week
case 'W':
return $this->dayOfWeek();
# Month
case 'F':
return self::$messages['year_months'][$pMonth];
case 'm':
return sprintf('%02s', $pMonth);
case 'M':
return substr(self::$messages['year_months'][$pMonth], 0, 6);
case 'n':
return $pMonth;
case 't':
return static::isLeapYear($pYear) && ($pMonth == 12) ? 30 : static::$daysMonthJalali[ intval($pMonth) - 1 ];
# Quarter
case 'Q':
case 'q':
return self::$messages['quarters'][$this->quarter];
# Years
case 'L':
return intval($this->isLeapYear($pYear));
case 'Y':
case 'o':
return $pYear;
case 'y':
return substr($pYear, 2);
# Time
case 'a':
return static::$messages['phrase'][parent::format('a')];
case 'A':
return static::$messages['pharse'][parent::format('a') == 'am' ? 'ante_meridiem' : 'post_meridiem'];
case 'B':
case 'g':
case 'G':
case 'h':
case 'H':
case 's':
case 'u':
case 'i':
# Timezone
case 'e':
case 'I':
case 'O':
case 'P':
case 'T':
case 'Z':
return parent::format($char);
# Full Date/Time
case 'c':
return ($pYear . '-' . $pMonth . '-' . $pDay . ' ' . parent::format('H:i:s P'));
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'));
case 'U':
return $timestamp;
default:
return $char;
}
}
/**
* The format of the outputted date string (jalali equivalent of php date() function)
*
* @param string $format for example 'Y-m-d H:i:s'
* @return string
*/
protected function dateWord($format)
{
$timestamp = $this->getTimestamp();
list($gYear, $gMonth, $gDay, $gWeek) = explode('-', parent::format('Y-m-d-w'));
list($pYear, $pMonth, $pDay) = static::getJalali($gYear, $gMonth, $gDay);
$pWeek = $gWeek + 1;
if ($pWeek >= 7) {
$pWeek = 0;
}
$lengh = strlen($format);
$index = 0;
$result = '';
while ($index < $lengh) {
$char = $format[$index];
if ($char == '\\') {
$result .= $format[++$index];
$index++;
continue;
}
$output = $this->characterFormat($char, $timestamp, $pYear, $pMonth, $pDay, $pWeek);
if (is_numeric($output)) {
$output = (string) new Notowo($output, static::getLocale() == 'en' ? 'en' : 'fa');
}
$result .= $output;
$index++;
}
return $result;
}
/**
* return day number from first day of year
*
* @param int $month
* @param int $day
* @return type
* @since 5.0.0
*/
protected function daysYear($month, $day)
{
$days = 0;
for ($i = 1; $i < $month; $i++) {
$days += static::$daysMonthJalali[$i - 1];
}
return ($days + $day);
}
/**
* return week number from first of year
*
* @param int $month
* @param int $day
* @return type
* @since 5.0.0
*/
protected function dayOfWeek()
{
$offset = $this->clone()->startYear()->format('w');
$days = $this->format('z');
return ceil(($days + $offset) / 7);
}
/**
* The format of the outputted date string (jalali equivalent of php strftime() function)
*
* @param $format
* @return string
*/
protected function strftime($format)
{
$strftime_date = [
"%a" => "D",
"%A" => "l",
"%d" => "d",
"%e" => "j",
"%j" => "z",
"%u" => "N",
"%w" => "w",
"%U" => "W",
"%V" => "W",
"%W" => "W",
"%b" => "M",
"%B" => "F",
"%h" => "M",
"%m" => "m",
"%C" => "y",
"%g" => "y",
"%G" => "y",
"%y" => "y",
"%Y" => "Y",
"%H" => "H",
"%I" => "h",
"%l" => "g",
"%M" => "i",
"%p" => "A",
"%P" => "a",
"%r" => "h:i:s A",
"%R" => "H:i",
"%S" => "s",
"%T" => "H:i:s",
"%X" => "h:i:s",
"%z" => "H",
"%Z" => "H",
"%c" => "D j M H:i:s",
"%D" => "d/m/y",
"%F" => "Y-m-d",
"%s" => "U",
"%x" => "d/m/y",
"%n" => "\n",
"%t" => "\t",
"%%" => "%",
"%Q" => "q",
"%q" => "q",
];
return str_replace(array_keys($strftime_date), array_values($strftime_date), $format);
}
/**
* The format of the outputted date string (jalali equivalent of php strftime() function)
*
* @param string $format
* @return string
*/
#[ReturnTypeWillChange]
public function format($format)
{
return $this->date($this->strftime($format));
}
/**
* The format of the outputted date string (gregorian)
*
* @param string $format
* @return string
*/
public function formatGregorian(string $format): string
{
return $this->datetime()->format($format);
}
/**
* Format the instance as date
*
* @return string
*/
public function formatDatetime(): string
{
return $this->format('Y-m-d H:i:s');
}
/**
* Format the instance as date
*
* @return string
*/
public function formatDate()
{
return $this->format('Y-m-d');
}
/**
* Format the instance as time
*
* @return string
*/
public function formatTime()
{
return $this->format('H:i:s');
}
/**
* Format the instance as date
*
* @return string
*/
public function formatJalaliDatetime()
{
return $this->format('Y/n/j H:i:s');
}
/**
* Format the instance as date
*
* @return string
*/
public function formatJalaliDate()
{
return $this->format('Y/n/j');
}
/**
* get difference in all
*
* @param Verta|null $v
*
* @return string
*/
public function formatDifference(Verta $v = null)
{
$units = [
static::SECONDS_PER_MINUTE,
static::MINUTES_PER_HOUR,
static::HOURS_PER_DAY,
static::DAYS_PER_WEEK,
static::WEEKS_PER_MONTH,
static::MONTHS_PER_YEAR,
static::YEARS_PER_DECADE,
static::DECADE_PER_CENTURY,
];
$difference = $this->diffSeconds($v);
$absolute = static::$messages['phrase'][$difference < 0 ? 'later' : 'ago'];
$difference = abs($difference);
for ($unit = 0; $difference >= $units[$unit] and $unit < count($units) - 1; $unit++) {
$difference /= $units[$unit];
}
$difference = intval(round($difference));
if ($difference === 0) {
return static::$messages['phrase']['now'];
}
return sprintf('%s %s %s', $difference, array_values(static::$messages['date_units'])[$unit], $absolute);
}
public function formatWord($format)
{
return $this->dateWord($this->strftime($format));
}
/**
* Convert english numbers to persian numbers
*
* @param string $string
* @return string
*/
public static function enToFaNumbers($string)
{
$en = static::getMessages('en');
$fa = static::getMessages('fa');
return str_replace(array_values($en['numbers']), array_values($fa['numbers']), $string);
}
/**
* Convert english numbers to persian numbers
*
* @param string $string
* @return string
*/
public static function faToEnNumbers($string)
{
$fa = static::getMessages('fa');
$en = static::getMessages('en');
return str_replace(array_values($fa['numbers']), array_values($en['numbers']), $string);
}
/**
* Convert english numbers to persian numbers
*
* @param string $string
* @return string
*/
public static function arToEnNumbers($string)
{
$ar = static::getMessages('ar');
$en = static::getMessages('en');
return str_replace(array_values($ar['numbers']), array_values($en['numbers']), $string);
}
}
-370
View File
@@ -1,370 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Modification
{
/**
* Add years to the instance. Positive $value travel forward while
* negative $value travel into the past.
*
* @param int $value
*
* @return static
*/
public function addYears($value)
{
return $this->year($this->year + $value);
}
/**
* Add a year to the instance
*
* @param int $value
*
* @return static
*/
public function addYear($value = 1)
{
return $this->addYears($value);
}
/**
* Remove years from the instance.
*
* @param int $value
*
* @return static
*/
public function subYears($value)
{
return $this->addYears(-1 * $value);
}
/**
* Remove a year from the instance
*
* @param int $value
*
* @return static
*/
public function subYear($value = 1)
{
return $this->subYears($value);
}
/**
* Add months to the instance. Positive $value travels forward while
* negative $value travels into the past.
*
* @param int $value
*
* @return static
*/
public function addMonths($value)
{
list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-m-d-H-i-s'));
$month += $value;
if ($month > 12) {
$year += intval($month / 12);
$month = $month % 12;
} elseif ($month < 1) {
$year += intval($month / 12) - 1;
$month = 12 + ($month % 12);
}
if ($month == 0) {
$year--;
$month = 12;
}
if (($month > 6 && $month < 12 && $day == 31)) {
$day--;
} else {
if ($month == 12 && ($day == 30 || $day == 31)) {
$day = self::isLeapYear($year) ? 30 : 29;
}
}
return self::createJalali($year, $month, $day, $hour, $minute, $second, $this->getTimeZone());
}
/**
* Add a month to the instance
*
* @param int $value
*
* @return static
*/
public function addMonth($value = 1)
{
return $this->addMonths($value);
}
/**
* Remove a month from the instance
*
* @param int $value
*
* @return static
*/
public function subMonth($value = 1)
{
return $this->subMonths($value);
}
/**
* Remove months from the instance
*
* @param int $value
*
* @return static
*/
public function subMonths($value)
{
return $this->addMonths(-1 * $value);
}
/**
* Add days to the instance. Positive $value travels forward while
* negative $value travels into the past.
*
* @param int $value
*
* @return static
*/
public function addDays($value)
{
return $this->modify((int) $value.' day');
}
/**
* Add a day to the instance
*
* @param int $value
*
* @return static
*/
public function addDay($value = 1)
{
return $this->addDays($value);
}
/**
* Remove a day from the instance
*
* @param int $value
*
* @return static
*/
public function subDay($value = 1)
{
return $this->subDays($value);
}
/**
* Remove days from the instance
*
* @param int $value
*
* @return static
*/
public function subDays($value)
{
return $this->addDays(-1 * $value);
}
/**
* Add weeks to the instance. Positive $value travels forward while
* negative $value travels into the past.
*
* @param int $value
*
* @return static
*/
public function addWeeks($value)
{
return $this->modify((int) $value.' week');
}
/**
* Add a week to the instance
*
* @param int $value
*
* @return static
*/
public function addWeek($value = 1)
{
return $this->addWeeks($value);
}
/**
* Remove a week from the instance
*
* @param int $value
*
* @return static
*/
public function subWeek($value = 1)
{
return $this->subWeeks($value);
}
/**
* Remove weeks to the instance
*
* @param int $value
*
* @return static
*/
public function subWeeks($value)
{
return $this->addWeeks(-1 * $value);
}
/**
* Add hours to the instance. Positive $value travels forward while
* negative $value travels into the past.
*
* @param int $value
*
* @return static
*/
public function addHours($value)
{
return $this->modify((int) $value.' hour');
}
/**
* Add an hour to the instance
*
* @param int $value
*
* @return static
*/
public function addHour($value = 1)
{
return $this->addHours($value);
}
/**
* Remove an hour from the instance
*
* @param int $value
*
* @return static
*/
public function subHour($value = 1)
{
return $this->subHours($value);
}
/**
* Remove hours from the instance
*
* @param int $value
*
* @return static
*/
public function subHours($value)
{
return $this->addHours(-1 * $value);
}
/**
* Add minutes to the instance. Positive $value travels forward while
* negative $value travels into the past.
*
* @param int $value
*
* @return static
*/
public function addMinutes($value)
{
return $this->modify((int) $value.' minute');
}
/**
* Add a minute to the instance
*
* @param int $value
*
* @return static
*/
public function addMinute($value = 1)
{
return $this->addMinutes($value);
}
/**
* Remove a minute from the instance
*
* @param int $value
*
* @return static
*/
public function subMinute($value = 1)
{
return $this->subMinutes($value);
}
/**
* Remove minutes from the instance
*
* @param int $value
*
* @return static
*/
public function subMinutes($value)
{
return $this->addMinutes(-1 * $value);
}
/**
* Add seconds to the instance. Positive $value travels forward while
* negative $value travels into the past.
*
* @param int $value
*
* @return static
*/
public function addSeconds($value)
{
return $this->modify((int) $value.' second');
}
/**
* Add a second to the instance
*
* @param int $value
*
* @return static
*/
public function addSecond($value = 1)
{
return $this->addSeconds($value);
}
/**
* Remove a second from the instance
*
* @param int $value
*
* @return static
*/
public function subSecond($value = 1)
{
return $this->subSeconds($value);
}
/**
* Remove seconds from the instance
*
* @param int $value
*
* @return static
*/
public function subSeconds($value)
{
return $this->addSeconds(-1 * $value);
}
}
-89
View File
@@ -1,89 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Transformation
{
/**
* gregorian to jalali convertion
*
* @param int $g_y
* @param int $g_m
* @param int $g_d
* @return array
*/
public static function getJalali($g_y, $g_m, $g_d)
{
$gy = $g_y - 1600;
$gm = $g_m - 1;
$g_day_no = (365 * $gy + intval(($gy + 3) / 4) - intval(($gy + 99) / 100) + intval(($gy + 399) / 400));
for ($i = 0; $i < $gm; ++$i) {
$g_day_no += static::$daysMonthGregorian[$i];
}
if ($gm > 1 && (($gy % 4 == 0 && $gy % 100 != 0) || ($gy % 400 == 0))) {
# leap and after Feb
$g_day_no++;
}
$g_day_no += $g_d - 1;
$j_day_no = $g_day_no - 79;
$j_np = intval($j_day_no / 12053); # 12053 = (365 * 33 + 32 / 4)
$j_day_no = $j_day_no % 12053;
$jy = (979 + 33 * $j_np + 4 * intval($j_day_no / 1461)); # 1461 = (365 * 4 + 4 / 4)
$j_day_no %= 1461;
if ($j_day_no >= 366) {
$jy += intval(($j_day_no - 1) / 365);
$j_day_no = ($j_day_no - 1) % 365;
}
for ($i = 0; ($i < 11 && $j_day_no >= static::$daysMonthJalali[$i]); ++$i) {
$j_day_no -= static::$daysMonthJalali[$i];
}
return [$jy, $i + 1, $j_day_no + 1];
}
/**
* jalali to gregorian convertion
*
* @param int $j_y
* @param int $j_m
* @param int $j_d
* @return array
*/
public static function getGregorian($j_y, $j_m, $j_d)
{
$jy = $j_y - 979;
$jm = $j_m - 1;
$j_day_no = (365 * $jy + intval($jy / 33) * 8 + intval(($jy % 33 + 3) / 4));
for ($i = 0; $i < $jm; ++$i) {
$j_day_no += static::$daysMonthJalali[$i];
}
$j_day_no += $j_d - 1;
$g_day_no = $j_day_no + 79;
$gy = (1600 + 400 * intval($g_day_no / 146097)); # 146097 = (365 * 400 + 400 / 4 - 400 / 100 + 400 / 400)
$g_day_no = $g_day_no % 146097;
$leap = 1;
if ($g_day_no >= 36525) { # 36525 = (365 * 100 + 100 / 4)
$g_day_no--;
$gy += (100 * intval($g_day_no / 36524)); # 36524 = (365 * 100 + 100 / 4 - 100 / 100)
$g_day_no = $g_day_no % 36524;
if ($g_day_no >= 365) {
$g_day_no++;
} else {
$leap = 0;
}
}
$gy += (4 * intval($g_day_no / 1461)); # 1461 = (365 * 4 + 4 / 4)
$g_day_no %= 1461;
if ($g_day_no >= 366) {
$leap = 0;
$g_day_no--;
$gy += intval($g_day_no / 365);
$g_day_no = ($g_day_no % 365);
}
for ($i = 0; $g_day_no >= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap)); $i++) {
$g_day_no -= (static::$daysMonthGregorian[$i] + ($i == 1 && $leap));
}
return [$gy, $i + 1, $g_day_no + 1];
}
}
-102
View File
@@ -1,102 +0,0 @@
<?php
namespace Hekmatinasser\Verta\Traits;
trait Translator
{
/**
* List of custom localized messages.
*
* @var array
*/
public static $messages = [];
/**
* List of custom localized messages.
*
* @var array
*/
public static $locale;
/**
* Reset the format used to the default when type juggling a Verta instance to a string
*/
public static function resetLocale()
{
static::setStringFormat(static::DEFAULT_LOCALE);
}
/**
* Set the default locale
*
* @param string $locale
*/
public static function setLocale($locale)
{
if ($messages = static::loadMessages($locale)) {
static::$locale = $locale;
}
return $messages;
}
/**
* Get the default locale
*
* @param string $locale
*/
public static function getLocale()
{
return static::$locale ?: static::DEFAULT_LOCALE;
}
/**
* Return a singleton instance of Translator.
*
* @param string|null $locale optional initial locale ("fa" - by default)
*
* @return bool
*/
public static function loadMessages($locale = null)
{
if ($messages = static::getMessages($locale)) {
static::$messages = $messages;
return true;
}
return false;
}
/**
* Set messages of a locale and take file first if present.
*
* @param string $locale
*
* @return mixed
*/
public static function getMessages($locale = null)
{
if (file_exists($filename = dirname(__DIR__).'/Lang/'.($locale ?: static::getLocale()).'.php')) {
return require $filename;
}
return false;
}
/**
* Set messages of a locale and take file first if present.
*
* @param string $locale
* @param array $messages
*
* @return $this
*/
public function setMessages($locale, $messages)
{
if (static::loadMessages($locale)) {
static::$messages = array_merge(static::$messages, $messages);
}
static::$messages = $messages;
}
}
+3 -4
View File
@@ -2,10 +2,9 @@
namespace Hekmatinasser\Verta;
use DateTime;
use Hekmatinasser\Verta\Traits\Date;
use Hekmatinasser\Jalali\Jalali;
class Verta extends DateTime implements VertaInterface
class Verta extends Jalali
{
use Date;
}
-41
View File
@@ -1,41 +0,0 @@
<?php
namespace Hekmatinasser\Verta;
interface VertaInterface
{
/**
* The day constants
*/
public const SATURDAY = 0;
public const SUNDAY = 1;
public const MONDAY = 2;
public const TUESDAY = 3;
public const WEDNESDAY = 4;
public const THURSDAY = 5;
public const FRIDAY = 6;
/**
* Number unit in date
*/
public const DECADE_PER_CENTURY = 10;
public const YEARS_PER_DECADE = 10;
public const MONTHS_PER_YEAR = 12;
public const MONTHS_PER_QUARTER = 3;
public const WEEKS_PER_YEAR = 52;
public const WEEKS_PER_MONTH = 4.35;
public const DAYS_PER_WEEK = 7;
public const HOURS_PER_DAY = 24;
public const MINUTES_PER_HOUR = 60;
public const SECONDS_PER_MINUTE = 60;
/**
* Word use in format datetime.
*/
public const DEFAULT_STRING_FORMAT = 'Y-m-d H:i:s';
/**
* Word use in format datetime.
*/
public const DEFAULT_LOCALE = 'fa';
}
+5 -3
View File
@@ -1,13 +1,15 @@
<?php
use Hekmatinasser\Verta\Verta;
if (! function_exists('verta')) {
/**
* @param null $datetime
* @param null $timezone
* @return \Hekmatinasser\Verta\Verta
* @return Verta
*/
function verta($datetime = null, $timezone = null)
function verta($datetime = null, $timezone = null): Verta
{
return new \Hekmatinasser\Verta\Verta($datetime, $timezone);
return new Verta($datetime, $timezone);
}
}