Verta

Verta 8

The verta is package for change solar calendar and gregorian together and provide helper function to use date and time.

Verta extend class PHP Datetime and compatible with Laravel PHP freamework and Carbon Package.

Verta use algorithm transform jalali to gregorian and revert. This transformer Jalali Calendar written Vahid Sohrablo, Rozbeh Pournader and Mohammad Tosi.

This package has been created by Nasser Hekmati under the license of MIT.

GitHub Logotype

Installation

command install verta


composer require hekmatinasser/verta

Usage

Use top of each file of the use Verta class


use Hekmatinasser\Verta\Verta;

Instantiate

verta(datetime, timezone)

To get the datetime

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo new Verta();
// output 1401-03-26 15:32:12

verta(datetime, timezone)

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo verta('2019-01-01 10:20:11');
// output 11397-10-11 10:20:11

now(timezone)

To get the current datetime

Arguments

  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::now();
// output 1401-03-26 15:32:12

today(timezone)

To get the start today datetime

Arguments

  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::today();
// if now 1401-03-26 15:32:12
// output 1401-03-26 00:00:00

tomorrow(timezone)

To get the start tomorrow datetime

Arguments

  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::tomorrow();
// if now 1401-03-26 00:00:00
// output 1401-03-27 00:00:00

yesterday(timezone)

To get the start yesterday datetime

Arguments

  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::yesterday();
// if now 1401-03-26 00:00:00
// output 1401-03-25 00:00:00

verta(datetime, timezone)

To get the add interval current date

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo verta('+2 month');
// if now 1401-03-26 00:00:00
// output 1401-05-26 00:00:00

verta(datetime, timezone)

To get the sub interval current date

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo verta('-1 day');
// if now 1401-03-26 00:00:00
// output 1401-03-25 00:00:00

verta(datetime, timezone)

To get the next interval current date

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo verta('next sunday');
// if now 1401-03-26 00:00:00 thursday
// output 1401-03-29 00:00:00

verta(datetime, timezone)

To get the last interval current date

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo verta('last friday');
// if now 1401-03-26 00:00:00 thursday
// output 1401-03-20 00:00:00

instance(datetime, timezone)

To get the datetime with static access

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::instance()
// output 1401-03-20 15:32:21

echo Verta::instance('2019-01-01 10:20:11');
// output 1397-10-11 10:20:11

verta(datetime, timezone)

To get the datetime with timestamp

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo verta(1583501791);
// output 1398-12-16 13:36:31

copy()

To get copy instance object for manipulate

Return

Verta

Example

$datetime = verta('2019-01-01 10:20:11');
$copy = $datetime->copy()->addDay();
echo $datetime;
// output 1397-10-11 10:20:11
echo $copy;
// output 1397-10-12 10:20:11

clone()

To get copy instance object for manipulate. same copy

Return

Verta

Example

$datetime = verta('2019-01-01 10:20:11');
$clone = $datetime->clone()->addDay();
echo $datetime;
// output 1397-10-11 10:20:11
echo $clone;
// output 1397-10-12 10:20:11

parse(datetime, timezone)

To get the verta datetime as a specific string verta

Arguments

  • string: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::parse('1395-10-07 14:12:32');
// output 1395-10-07 14:12:32

echo Verta::parse('1396 مهر 17');
// output 1396-07-07 00:00:00

parseFormat(format, datetime, timezone)

To get the verta datetime as a specific string verta

Arguments

  • string: format
  • string: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::parseFormat('Y n j','1396 مهر 17')
// output 1396-07-07 00:00:00

create(year, month, day, hour, minute, second, timezone)

To get the verta datetime form separate gregorian date and time

Arguments

  • int: year
  • int: month
  • int: day
  • int: hour
  • int: minute
  • int: second
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::create(2016,12,25,15,20,15);
// output 1395-10-05 15:20:15

createDate(year, month, day, timezone)

To get the verta datetime form separate gregorian date. hour, minute and second set now

Arguments

  • int: year
  • int: month
  • int: day
  • TimeZone|string|null: timezone

Return

Verta

Example

Verta::createDate(2016,12,25);
// if now 1398-02-28 15:20:15
// output 1395-10-05 15:20:15

createTime(hour, minute, second, timezone)

To get the verta datetime form separate gregorian date and time. year, month and day set now

Arguments

  • int: hour
  • int: minute
  • int: second
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createTime(15,20,15);
// if now 1395-10-05 23:18:53
// output 1395-10-05 15:20:15

createGregorian(year, month, day, hour, minute, second, timezone)

To get the verta datetime form separate gregorian date and time

Arguments

  • int: year
  • int: month
  • int: day
  • int: hour
  • int: minute
  • int: second
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createGregorian(2016,12,25,15,20,15);
// output 1395-10-05 15:20:15

createDate(year, month, day, timezone)

To get the verta datetime form separate gregorian date. hour, minute and second set now

Arguments

  • int: year
  • int: month
  • int: day
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createGregorianDate(2016,12,25);
// if now 1398-02-28 15:20:15
// output 1395-10-05 15:20:15

createTime(hour, minute, second, timezone)

To get the verta datetime form separate gregorian date and time. year, month and day set now

Arguments

  • int: hour
  • int: minute
  • int: second
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createGregorianTime(15,20,15);
// if now 1395-10-05 23:18:53
// output 1395-10-05 15:20:15

createTimestamp(datetime, timezone)

Arguments

  • number: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createTimestamp(1583501791)
// output 1398-12-16 13:36:31

createJalali(year, month, day, hour, minute, second, timezone)

To get the verta datetime form separate verta date and time

Arguments

  • int: year
  • int: month
  • int: day
  • int: hour
  • int: minute
  • int: second
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createJalali(1394,12,29,15,51,5);
// output 1394-12-29 15:51:05

createJalaliDate(year, month, day, timezone)

To get the verta datetime form separate verta date. hour, minute and second set now

Arguments

  • int: year
  • int: month
  • int: day
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createJalali(1394,12,29);
// if now 1399-12-23 15:51:05
// output 1394-12-29 15:51:05

createJalaliTime(hour, minute, second, timezone)

To get the verta datetime form separate verta date. year, month and day set now

Arguments

  • int: hour
  • int: minute
  • int: second
  • TimeZone|string|null: timezone

Return

Verta

Example

echo Verta::createJalali(15,51,5);
// if now 1394-12-29 13:22:44
// output 1394-12-29 15:51:05

Transformation

jalaliToGregorian(year, month, day)

To get the verta datetime form separate gregorian date.

Arguments

  • int: hour
  • int: minute
  • int: second

Return

array

Example

vardump(Verta::jalaliToGregorian(1401,03,27));
// output [2020,6,17]

GregorianToJalali(year, month, day)

To get the verta datetime form separate gregorian date.

Arguments

  • int: hour
  • int: minute
  • int: second

Return

array

Example

var_dump(Verta::GregorianToJalali(2020,6,17));
// output [1401,03,27]

datetime()

To get the object Datetime php

Return

object Datetime php

Example

echo verta()->datetime();
// if now 1397-10-11 10:20:11
// output 2019-01-01 10:20:11

toJalali()

To get the object Verta from carbon

Return

Verta

Example

echo now()->toJalali();
// if now 2019-01-01 10:20:11
// output 1397-10-11 10:20:11

toCarbon()

Return

Carbon

Example

echo verta()->toCarbon();
// output '2019-01-01 10:20:11'

verta(datetime, timezone)

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

$datetime = new Datetime('2019-01-01 10:20:11');
echo verta($datetime);
// output 1397-10-11 10:20:11

verta(datetime, timezone)

To get the datetime with Carbon

Arguments

  • DateTime|string|number|null: datetime
  • TimeZone|string|null: timezone

Return

Verta

Example

$datetime = new Carbon('2019-01-01 10:20:11');
echo verta($datetime);
// output 1397-10-11 10:20:11

Getter

year

To get year on object verta

Return

int

Example

$datetime = verta();
// if now 1397-10-11 10:20:11
echo$datetime->year
// output 1397

month

To get month on object verta

Return

int

Example

$datetime = verta();
// if now 1397-10-11 15:20:11
echo $datetime->year;
// output 10

day

To get day on object verta

Return

int

Example

$datetime = verta();
// if now 1397-10-11 10:20:11
echo $datetime->year;
// output 11

hour

To get hour on object verta

Return

int

Example

$datetime = verta();
// if now 1397-09-11 10:20:11
echo $datetime->hour;
// output 10

minute

To get minute on object verta

Return

int

Example

$datetime = verta();
// if now 1397-10-11 10:20:11
echo $datetime->minute;
// output 20

second

To get second on object verta

Return

int

Example

$datetime = verta();
// if now 1397-10-11 10:20:33
echo $datetime->hour
// output 33

micro

To get micro on object verta

Return

int

Example

$datetime = verta();
// if now 1397-10-11 10:20:11.123843
echo $datetime->micro;
// output 123843

timestamp

To get timestamp on object verta

Return

int

Example

$datetime = verta();
// if now 1396-03-14 14:18:23
echo $datetime->timestamp;
// output 1496557661

timezone

To get timezone on object verta

Return

string

Example

$datetime = verta();
// if now 1396-03-14 14:18:23
echo $datetime->timezone;
// output Asia/Tehran

dayOfWeek

To get dayOfWeek on object verta

Return

int

Example

$datetime = verta();
// if now friday
echo $datetime->dayOfWeek;
// output 6

dayOfYear

To get dayOfYear on object verta

Return

int

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->dayOfYear;
// output 45

daysInMonth

To get daysInMonth on object verta

Return

int

Example

$datetime = verta();
// if now 1396-03-14 14:18:23
echo $datetime->daysInMonth;
// output 31

Setter

year

To set year on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->year = 1398;
echo $datetime;
// output 1398-02-14 14:18:23

month

To set month on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->month = 13;
echo $datetime;
// output 1397-01-14 14:18:23

day

To set day on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->day = 25;
echo $datetime;
// output 1396-02-25 14:18:23

hour

To set hour on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->hour = 8;
echo $datetime;
// output 1396-02-25 8:18:23

minute

To set minute on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->minute = 25;
echo $datetime;
// output 1396-02-25 14:25:23

second

To set second on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->second = 55;
echo $datetime;
// output 1396-02-25 14:18:55

micro

To set micro on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->micro = 158265;
echo $datetime;
// output 1396-02-25 14:18:23.158265

timestamp

To set timestamp on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->timestamp = 1496557661;
echo $datetime;
// output 1396-03-14 14:18:23

timezone

To set timezone on object verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->timezone = 'Asia/Baku';
echo $datetime->timezone;
// output Asia/Baku

year(value)

To set year on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->year(1398);
// output 1398-02-14 14:18:23

month(value)

To set month on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->month(13);
// output 1397-01-14 14:18:23

day(value)

To set day on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->day(25);
// output 1396-02-25 14:18:23

hour(value)

To set hour on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->hour(8);
// output 1396-02-25 8:18:23

minute(value)

To set minute on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->minute(25);
// output 1396-02-25 14:25:23

second(value)

To set second on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->second(55);
// output 1396-02-25 14:18:55

micro(value)

To set micro on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->micro(158265);
// output 1396-02-25 14:18:23.158265

timestamp(value)

To set timestamp on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
$datetime->timestamp(1496557661);
// output 1396-03-14 14:18:23

timezone()

To set timezone on object verta

Arguments

  • int: value

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->timezone('Asia/Baku');
// output Asia/Baku

setDateTime(year, month, day, hour, minute, second, micro)

To set date and time on object verta

Arguments

  • int: year
  • int: month
  • int: day
  • int: hour
  • int: minute
  • int: second
  • int: micro

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->setDateTime(1395, 4, 25, 16, 50, 42);
// output 1395-04-25 16:50:42

setDate(year, month, day)

To set date on object verta

Arguments

  • int: year
  • int: month
  • int: day

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->setDate(2022, 6, 17);
// output 1401-03-27 16:50:42

setDateJalali(year, month, day)

To set date on object verta

Arguments

  • int: year
  • int: month
  • int: day

Return

Verta

Example

$datetime = verta();
// if now 1396-02-14 14:18:23
echo $datetime->setDateJalali(1401,3,17);
// output 1401-03-27 16:50:42

setTimeString(time)

To set time on object verta

Arguments

  • string: time

Return

Verta

Example

$datetime = verta();
// if now 1401-03-27 14:18:23
echo $datetime->setTimeString('12:25:45.695321');
// output 1401-03-27 12:25:45.695321
echo $datetime->setTimeString('12:25:45');
// output 1401-03-27 12:25:45
echo $datetime->setTimeString('12:25');
// output 1401-03-27 12:25:00
echo $datetime->setTimeString('12:25');
// output 1401-03-27 12:25:00
echo $datetime->setTimeString('12');
// output 1401-03-27 12:00:00

Formatting

format(format)

To represent date and time format

To create the format you want read the PHP document strftime and date.

Arguments

  • string: format

Return

string

Example

echo verta()->format('Y-n-j H:i');
// output 1395-10-7 14:12
echo verta()->format('%B %d، %Y');
// output دی 7، 1395
echo verta()->format('%Q %Y');
// output زمستان 1395
echo verta();
// output 1395-10-07 14:12:25

formatDatetime()

To represent date and time format

Return

string

Example

echo verta()->formatDatetime();
// output 1395-10-07 14:12:25

formatDate()

To represent date format

Return

string

Example

echo verta()->formatDate();
// output 1395-10-07

formatTime()

To represent time format

Return

string

Example

echo verta()->formatTime();
// output 14:12:25

formatJalaliDatetime()

To represent verta date format

Return

string

Example

echo verta()->formatJalaliDatetime();
// output 1395/10/07 14:12:25

formatJalaliDate()

To represent verta date format

Return

string

Example

echo verta()->formatJalaliDate();
// output 1395/10/07

formatGregorian(format)

To represent date and time format gregorian

To create the format you want read the PHP document strftime and date.

Arguments

  • string: format

Return

string

Example

echo verta()->formatGregorian('Y-n-j H:i');
// output 2017-05-23 23:21:02

formatJalaliDate(datetime)

To display the date difference as a unit of time. If don't set parameter, the difference is calculated with the current time

Arguments

  • verta: datetime

Return

string

Example

echo verta()->formatDifference(verta('+1 year'));
// output 1 سال بعد
echo verta()->formatDifference(verta('-1 year'));
// output 1 سال قبل
echo verta('+25 day')->formatDifference();
// output 4 هفته بعد
echo verta('-6 day')->formatDifference();
// output 6 روز قبل
echo verta()->formatDifference();
// output الان

formatWord(format)

To display numbers in alphabetical

Arguments

  • string: format

Return

string

Example

echo verta()->formatWord('Y');
// output یک هزار و سیصد و نود و شش
echo verta()->formatWord('l dS F');
// output چهارشنبه بیست و نه ام شهریور
echo verta()->formatWord('d F Y');
// output بیست و نه شهریور یک هزار و سیصد و نود و شش

formatJalaliDate(format)

To set default output format

Arguments

  • string: format

Example

Verta::setFormat('Y/n/j H:i:s');
echo verta(); // output 1395/12/12 00:11:35

undefined

To reset output format

Example

Verta::resetFormat('Y/n/j H:i:s');
echo verta(); // output 1395-12-12 00:18:04

Modification

addYear()

To increment a year verta date

Return

Verta

Example

echo verta()->addYear();
// if now 1395-10-07 14:12:32
// output 1396-10-07 14:12:32

addYears(value)

To increment years verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->addYears(3);
// if now 1395-10-07 14:12:32
// output 1398-10-07 14:12:32

subYear()

To decrement a year verta date

Return

Verta

Example

echo verta()->subYear();
// if now 1395-10-07 14:12:32
// output 1394-10-07 14:12:32

subYears(value)

To decrement years verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->subYears(3);
// if now 1395-10-07 14:12:32
// output 1392-10-07 14:12:32

addMonth()

To increment a month verta date

Return

Verta

Example

echo verta()->addMonth();
// if now 1395-10-07 14:12:32
// output 1395-11-07 14:12:32

addMonths(value)

To increment months verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->addMonth(2);
// if now 1395-10-07 14:12:32
// output 1395-12-07 14:12:32

subMonth()

To decrement a month verta date

Return

Verta

Example

echo verta()->subMonth();
// if now 1395-10-07 14:12:32
// output 1395-09-07 14:12:32

subMonths(value)

To decrement months verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->subMonths(3);
// if now 1395-10-07 14:12:32
// output 1395-07-07 14:12:32

addWeek()

To increment a week verta date

Return

Verta

Example

echo verta()->addMonth();
// if now 1395-10-07 14:12:32
// output 1395-10-14 14:12:32

undefined

To increment weeks verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->addWeeks(3);
// if now 1395-10-07 14:12:32
// output 1395-12-28 14:12:32

subWeek()

To decrement a week verta date

Return

Verta

Example

echo verta()->subWeek();
// if now 1395-10-07 14:12:32
// output 1395-09-30 14:12:32

subWeeks(value)

To decrement weeks verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->subWeeks(3);
// if now 1395-10-07 14:12:32
// output 1395-09-16 14:12:32

addDay()

To increment a day verta date

Return

Verta

Example

echo verta()->addDay();
// if now 1395-10-07 14:12:32
// output 1395-10-08 14:12:32

undefined

To increment days verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->addWeeks(3);
// if now 1395-10-07 14:12:32
// output 1395-10-10 14:12:32

subDay()

To decrement a day verta date

Return

Verta

Example

echo verta()->subDay();
// if now 1395-10-07 14:12:32
// output 1395-10-06 14:12:32

subDays(value)

To decrement days verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->subDays(3);
// if now 1395-10-07 14:12:32
// output 1395-10-04 14:12:32

addHour()

To increment a day verta date

Return

Verta

Example

echo verta()->addHour();
// if now 1395-10-07 14:12:32
// output 1395-10-07 15:12:32

addHours()

To increment days verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->addHours(3);
// if now 1395-10-07 14:12:32
// output 1395-10-07 17:12:32

subHour()

To decrement a hour verta date

Return

Verta

Example

echo verta()->subHour();
// if now 1395-10-07 14:12:32
// output 1395-10-07 13:12:32

subHours(value)

To decrement hours verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->subHours(3);
// if now 1395-10-07 14:12:32
// output 1395-10-07 11:12:32

addMinute()

To increment a minute verta date

Return

Verta

Example

echo verta()->addMinute();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:13:32

addMinutes(value)

To increment minutes verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->addMinutes(3);
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:15:32

subMinute()

To decrement a minute verta date

Return

Verta

Example

echo verta()->subMinute();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:11:32

subMinutes(value)

To decrement minutes verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->subMinutes(3);
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:09:32

addSecond()

To decrement a second verta date

Return

Verta

Example

echo verta()->addSecond();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:12:33

addSeconds(value)

To increment minutes verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->addSeconds(3);
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:12:35

subSecond()

To decrement a second verta date

Return

Verta

Example

echo verta()->subSecond();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:12:31

subSeconds(value)

To decrement seconds verta date

Arguments

  • int: value

Return

Verta

Example

echo verta()->subSeconds(3);
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:12:29

Boundaries

startYear()

To start year verta date

Return

Verta

Example

echo verta()->startYear();
// if now 1395-10-07 14:12:32
// output 1395-01-01 00:00:00

endYear()

To end year verta date

Return

Verta

Example

echo verta()->endYear();
// if now 1395-10-07 14:12:32
// output 1395-12-30 23:59:59

startQuarter()

To start quarter verta date

Return

Verta

Example

echo verta()->startQuarter();
// if now 1395-11-07 14:12:32
// output 1395-10-01 00:00:00

endQuarter()

To end quarter verta date

Return

Verta

Example

echo verta()->endQuarter();
// if now 1395-11-07 14:12:32
// output 1395-12-30 23:59:59

startMonth()

To start month verta date

Return

Verta

Example

echo verta()->startMonth();
// if now 1395-10-07 14:12:32
// output 1395-10-01 00:00:00

endMonth()

To end month verta date

Return

Verta

Example

echo verta()->endMonth();
// if now 1395-10-07 14:12:32
// output 1395-10-30 23:59:59

startWeek()

To start week verta date

Return

Verta

Example

echo verta()->startWeek();
// if now 1395-10-07 14:12:32
// output 1395-10-04 00:00:00

endWeek()

To end week verta date

Return

Verta

Example

echo verta()->endWeek();
// if now 1395-10-07 14:12:32
// output 1395-10-10 23:59:59

startDay()

To start day verta date

Return

Verta

Example

echo verta()->startDay();
// if now 1395-10-07 14:12:32
// output 1395-10-07 00:00:00

endDay()

To end day verta date

Return

Verta

Example

echo verta()->endDay();
// if now 1395-10-07 14:12:32
// output 1395-10-07 23:59:59

startHour()

To start hour verta date

Return

Verta

Example

echo verta()->startHour();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:00:00

endHour()

To end hour verta date

Return

Verta

Example

echo verta()->endHour();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:59:59

startMinute()

To start minute verta date

Return

Verta

Example

echo verta()->startMinute();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:12:00

endMinute()

To start minute verta date

Return

Verta

Example

echo verta()->endMinute();
// if now 1395-10-07 14:12:32
// output 1395-10-07 14:12:59

Difference

diffYears(datetime)

To difference year datetime together.

Arguments

  • Varta|DateTime|string|number|null: datetime

Return

Verta

Example

echo verta('2017-05-15')->diffYears(verta('2018-05-15'))
 // output -1

diffMonths(datetime)

To difference month datetime together.

Arguments

  • Varta|DateTime|string|number|null: datetime

Return

Verta

Example

echo verta('2017-08-15')->diffYears()
// if now 2017-05-15
// output 3

diffWeeks(datetime)

To difference week datetime together.

Arguments

  • Varta|DateTime|string|number|null: datetime

Return

Verta

Example

echo verta('2017-05-15')->diffWeeks()
// if now 2017-05-15
 // output 2

diffDays(datetime)

To difference day datetime together.

Arguments

  • Varta|DateTime|string|number|null: datetime

Return

Verta

Example

echo verta('2017-05-15')->diffDays()
// if now 2017-05-18
 // output -3

diffHours(datetime)

To difference hour datetime together.

Arguments

  • Varta|DateTime|string|number|null: datetime

Return

Verta

Example

echo verta('2017-05-15 12:20:32')->diffDays()
// if now 2017-05-18 18:56:43
 // output -6

diffMinutes(datetime)

To difference minute datetime together.

Arguments

  • Varta|DateTime|string|number|null: datetime

Return

Verta

Example

echo verta('2017-05-15 12:20:32')->diffMinutes()
// if now 2017-05-18 12:56:43
 // output -36

diffSeconds(datetime)

To difference minute datetime together.

Arguments

  • Varta|DateTime|string|number|null: datetime

Return

Verta

Example

echo verta('2017-05-15 12:20:32')->diffSeconds()
// if now 2017-05-18 12:20:43
 // output -10

Comparison

eq(datetime)

To compere equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->eq(jalalai('-1 minute'));
// output false

equalTo(datetime)

To compere equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->equalTo();
// output true

ne(datetime)

To compere not equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->ne(jalalai('-1 minute'));
// output true

notEqualTo(datetime)

To compere not equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->notEqualTo();
// output false

gt(datetime)

To compere greater than datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->gt(jalalai('-5 minute'));
// output true

greaterThan(datetime)

To compere greater than datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->greaterThan();
// output false

gte(datetime)

To compere greater than or equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->gte();
// output true

greaterThanOrEqualTo(datetime)

To compere greater than or equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->greaterThanOrEqualTo(verta('+2 second'));
// output false

lt(datetime)

To compere less than datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->lt(verta('+2 second'));
// output true

lessThan(datetime)

To compere less than datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->lessThan(verta('-3 second'));
// output false

lte(datetime)

To compere less than or equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->lte();
// output true

lessThanOrEqualTo(datetime)

To compere less than or equal datetime together.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->lessThanOrEqualTo(verta('+2 hour'));
// output false

between(first, second, equal)

To compere less than or equal datetime together.

Arguments

  • Varta|DateTime|string|number|null: first
  • Varta|DateTime|string|number|null: second
  • bool: equal

Return

bool

Example

echo verta()->between(verta('+2 hour') , verta('+1 hour'));
// output false

closest(first, second)

To get closest datetime between two datetime.

Arguments

  • Varta|DateTime|string|number|null: first
  • Varta|DateTime|string|number|null: second

Return

Verta

Example

echo $first = verta('+2 hour');
// output 1398-03-15 21:22:23
 echo $second = verta('-1 hour');
// output 1398-03-15 18:22:23
 echo verta()->closest($first , $secound);
// output 1398-03-15 18:22:23

farthest(first, second)

To get farthest datetime between two datetime.

Arguments

  • Varta|DateTime|string|number|null: first
  • Varta|DateTime|string|number|null: second

Return

Verta

Example

echo $first = verta('+2 hour');
// output 1398-03-15 21:22:23
 echo $second = verta('-1 hour');
// output 1398-03-15 18:22:23
 echo verta()->farthest($first , $secound);
// output 1398-03-15 18:22:23

min(datetime)

To get minimum datetime between two datetime.

Arguments

  • Verta: datetime

Return

Verta

Example

echo $datetime = verta('-2 hour');
// output 1398-03-15 21:22:23
 echo verta()->min($datetime);
// output 1398-03-15 21:22:23

minimum(datetime)

To get minimum datetime between two datetime.

Arguments

  • Verta: datetime

Return

Verta

Example

echo $datetime = verta('+2 hour');
// output 1398-03-15 21:22:23
 echo verta()->min($datetime);
// output 1398-03-15 19:22:23

max(datetime)

To get maximum datetime between two datetime.

Arguments

  • Verta: datetime

Return

Verta

Example

echo $datetime = verta('+2 hour');
// output 1398-03-15 21:22:23
 echo verta()->max($datetime);
// output 1398-03-15 21:22:23

maximum(datetime)

To get maximum datetime between two datetime.

Return

bool

Example

echo $datetime = verta('-2 hour');
// output 1398-03-15 21:22:23
 echo verta()->maximum($datetime);
// output 1398-03-15 19:22:23

isWeekday()

To get datetime is in weekdays.

Return

Verta

Example

echo $datetime = verta()->format('j');
// output 19
 echo $datetime->isWeekday();
// output true

isWeekend()

To get datetime is in weekend days.

Return

bool

Example

echo $datetime = verta()->format('j');
// output جمعه
 echo $datetime->isWeekend();
// output true

isYesterday()

To get datetime is yesterday.

Return

bool

Example

echo verta()->isYesterday();
// output false

isToday()

To get datetime is today.

Return

bool

Example

echo verta()->isToday();
// output true

isNextWeek()

To get datetime is next week.

Return

bool

Example

echo verta('next week')->isNextWeek();
// output true

isLastWeek()

To get datetime is days last week.

Return

bool

Example

echo verta('previous week')->isLastWeek();
// output true

isNextMonth()

To get datetime is days next month.

Return

bool

Example

echo verta('+2 month')->isNextMonth();
// output false

isLastMonth()

To get datetime is days last month.

Return

bool

Example

echo verta('-35 day')->isLastMonth();
// output true

isNextYear()

To get datetime is days next year.

Return

bool

Example

echo verta('+12 month')->isNextYear();
// output true

isLastYear()

To get datetime is days last year.

Return

bool

Example

echo verta('+5 day')->isLastYear();
// output false

isFuture()

To get datetime is future.

Return

bool

Example

echo verta('+5 day')->isFuture();
// output true

isPast()

To get datetime is past.

Return

bool

Example

echo verta('-2 day')->isPast();
// output true

isCurrentYear()

To get datetime is current year.

Return

bool

Example

echo verta()->isCurrentYear();
// output true

isCurrentMonth()

To get datetime is current month.

Return

bool

Example

echo verta()->endMonth()->isCurrentMonth();
// output true

isSameAs(format, datetime)

To get datetime is same part of datetime.

Arguments

  • string: format
  • Varta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->isSameAs('y', verta()->startYear());
// output true

isSameYear(datetime)

To get datetime is same year datetime.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->isSameYear(verta()->startYear());
// output true

isSameMonth(datetime)

To get datetime is same month datetime.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->isSameMonth('y', verta()->startMonth());
// output true

isSameDay(datetime)

To get datetime is same day datetime.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->isSameDay(verta()->startDay());
// output true

isBirthday(datetime)

To get datetime is birthday datetime.

Arguments

  • Verta|DateTime|string|number|null: datetime

Return

bool

Example

echo verta()->isBirthday();
// output true

isSaturday()

To get datetime is suturday.

Return

bool

Example

echo verta()->startWeek()->isSaturday();
// output true

isSunday()

To get datetime is sunday.

Return

bool

Example

echo verta()->startWeek()->isSunday();
// output false

isMonday()

To get datetime is suturday.

Return

bool

Example

echo verta('next monday')->isMonday();
// output true

isTuesday()

To get datetime is tuesday.

Return

bool

Example

echo verta('previous tuesday')->isTuesday();
// output true

isWednesday()

To get datetime is wednesday.

Return

bool

Example

echo verta('next monday')->isWednesday();
// output false

isThursday()

To get datetime is thursday.

Return

bool

Example

echo verta('next monday')->isThursday();
// output false

isFriday()

To get datetime is friday.

Return

bool

Example

echo verta('next monday')->isFriday();
// output false

Validation

isLeapYear(year)

Check year is leap.

Arguments

  • int: year

Return

bool

Example

return Verta::isLeapYear(1394);
// output false

isValidDate(year, month, day)

Check date is valid.

Arguments

  • int: year
  • int: month
  • int: day

Return

bool

Example

return Verta::isValidDate(1394, 12, 30);
// output false

isValidTime(hour, minute, second)

Check time is valid.

Arguments

  • int: hour
  • int: minute
  • int: second

Return

bool

Example

return Verta::isValidTime(27, 52, 30);
// output false

validYear(value)

To valid year.

Arguments

  • int: value

Exception

InvalidUnitException

Example

Verta::validYear(-1);
// throw InvalidUnitException

validMount(value)

To valid month.

Arguments

  • int: value

Exception

InvalidUnitException

Example

Verta::validMount(13);
// throw InvalidUnitException

validDay(year, month, day)

To valid month.

Arguments

  • int: year
  • int: month
  • int: day

Exception

InvalidUnitException

Example

Verta::validDay(1400, 12, 30);
// throw InvalidUnitException

validHour(value)

To valid hour.

Arguments

  • int: value

Exception

InvalidUnitException

Example

Verta::validHour(30);
// throw InvalidUnitException

validMinute(value)

To valid minute.

Arguments

  • int: value

Exception

InvalidUnitException

Example

Verta::validMinute(60);
// throw InvalidUnitException
class="name">

validSecond(value)

To valid second.

Arguments

  • int: value

Exception

InvalidUnitException

Example

Verta::validSecond(60);
// throw InvalidUnitException

validMicro(value)

To valid micro.

Arguments

  • int: value

Exception

InvalidUnitException

Example

Verta::validMicro(1828888484);
// throw InvalidUnitException

validDate(year, month, day)

To valid date.

Arguments

  • int: year
  • int: month
  • int: day

Exception

InvalidUnitException

Example

Verta::validDate(1400, 12, 30);
// throw InvalidUnitException

validTime(hour, minute, second, micro)

To valid time.

Arguments

  • int: hour
  • int: minute
  • int: second
  • int|null: micro

Exception

InvalidUnitException

Example

Verta::validTime(25, 12, 30);
// throw InvalidUnitException

validDateTime(year, month, day, hour, minute, second, micro)

To valid datetime.

Arguments

  • int: year
  • int: month
  • int: day
  • int: hour
  • int: minute
  • int: second
  • int|null: micro

Exception

InvalidUnitException

Example

Verta::validDateTime(1400, 12, 30, 25, 12, 30);
// throw InvalidUnitException

Laravel Validation

To use rules for jalali datetime validation in laravel.

Append validation translate to langs/fa/validation.php file in laravel project. for other language use lang jalali package folder.


...
'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 باشد.',

'attributes' => [
    'start_date'      => 'تاریخ شروع',
    'expire_datetime' => 'تاریخ انقضا',
],
...

jdate:format

To validate date jalali.

Arguments

  • string|null: format

Example

dd(validator([
  'start_date' => '1389-01-31'
],[
  'start_date' => 'jdate:Y.m.d'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع معتبر نمی باشد."
  ]
]*/

jdatetime:format

To validate datetime jalali.

Arguments

  • string|null: format

Example

dd(validator([
  'start_date' => '1389-01-31 12:20:30'
],[
  'start_date' => 'jdate:Y.m.d H.i.s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع معتبر نمی باشد."
  ]
]*/

jdate_equal:date,format

To validate date equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389-01-31'
],[
  'start_date' => 'jdate_equal:1388/01/01,Y/m/d'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع برابر ۱۳۹۸/۱/۱ نمی باشد."
  ]
]*/

jdatetime_equal:datetime,format

To validate date equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389-01-31 12:20:30'
],[
  'start_date' => 'jdatetime_equal:1388/01/01 00:20:30,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع برابر ۱۳۹۸/۱/۱ ۰۰:۲۰:۳۰ نمی باشد."
  ]
]*/

jdate_not_equal:date,format

To validate date not equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31'
],[
  'start_date' => 'jdate_not_equal:1388/01/31,Y/m/d'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع برابر ۱۳۹۸/۱/۳۱ می باشد."
  ]
]*/

jdatetime_not_equal:datetime,format

To validate datetime not equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31'
],[
  'start_date' => 'jdatetime_not_equal:1388/01/31 00:20:30,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع برابر ۱۳۹۸/۱/۳۱ ۰۰:۲۰:۳۰ می باشد."
  ]
]*/

jdate_after:date,format

To validate datetime not equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31'
],[
  'start_date' => 'jdate_after:1388/01/31,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید بعد از ۱۳۹۸/۱/۳۱ باشد."
  ]
]*/

jdatetime_after:datetime,format

To validate datetime after jalali.

Arguments

  • string|null: datetime
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31 13:21:56'
],[
  'start_date' => 'jdatetime_after:1388/01/31 18:30:57,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید بعد از ۱۳۹۸/۱/۳۱ ۱۸:۳۰:۵۷ باشد."
  ]
]*/

jdate_after_equal:date,format

To validate date after or equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/30'
],[
  'start_date' => 'jdate_after_equal:1388/01/31,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید بعد یا برابر ۱۳۹۸/۱/۳۱ باشد."
  ]
]*/

jdatetime_after_equal:date,format

To validate datetime after or equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31 12:23:52'
],[
  'start_date' => 'jdatetime_after_equal:1388/01/31 12:23:54,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید بعد یا برابر ۱۳۹۸/۱/۳۱ ۱۲:۲۳:۵۴ باشد."
  ]
]*/

jdate_before:date,format

To validate date after jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31'
],[
  'start_date' => 'jdate_before:1388/01/31,Y/m/d'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید قبل از ۱۳۹۸/۱/۳۱ باشد."
  ]
]*/

jdatetime_before:datetime,format

To validate datetime before jalali.

Arguments

  • string|null: datetime
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31 13:21:58'
],[
  'start_date' => 'jdatetime_before:1388/01/31 10:30:57,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید قبل از ۱۳۹۸/۱/۳۱ ۱۰:۳۰:۵۷ باشد."
  ]
]*/

jdate_before_equal:date,format

To validate date after or equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/30'
],[
  'start_date' => 'jdate_before_equal:1388/01/28,Y/m/d'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید قبل یا برابر ۱۳۹۸/۱/۳۱ باشد."
  ]
]*/

jdatetime_before_equal:date,format

To validate datetime before or equal jalali.

Arguments

  • string|null: date
  • string|null: format

Example

dd(validator([
  'start_date' => '1389/01/31 12:23:55'
],[
  'start_date' => 'jdatetime_before_equal:1388/01/31 12:23:54,Y/m/d H:i:s'
])
->errors()
->messages());
/* output
[
  "start_date" => [
      "تاریخ شروع باید قبل یا برابر ۱۳۹۸/۱/۳۱ ۱۲:۲۳:۵۴ باشد."
  ]
]*/

Localization

setLocale(locale)

To set locale.

Arguments

  • string: locale

Example

Verta::setLocale('fa');

resetLocale()

To reset to default(fa) locale.

Example

Verta::resetLocale();

getLocale()

To get current locale

Return

string

Example

echo Verta::getLocale(); // output fa

setMessages(locale, messages)

To Append custom messages to locale.

Arguments

  • string: locale
  • array: messages

Example

Verta::setMessages('fa', ['weekdays.7' => 'آدینه']);
main.js:9:17