コード例 #1
0
ファイル: LeapTest.php プロジェクト: opencafe/datium
 public function testAssertLeapYear()
 {
     // 2012 is a leap year
     $this->assertEquals(true, Datium::create(2012, 1, 1, 0, 0, 0)->leap()->get());
     // 2013 is not leap year
     $this->assertEquals(false, Datium::create(2013, 1, 1, 0, 0, 0)->leap()->get());
     // 2014 is not leap year
     $this->assertEquals(false, Datium::create(2014, 1, 1, 0, 0, 0)->leap()->get());
     // 2015 is not leap year
     $this->assertEquals(false, Datium::create(2015, 1, 1, 0, 0, 0)->leap()->get());
     // 2015 is a leap year
     $this->assertEquals(true, Datium::create(2016, 1, 1, 0, 0, 0)->leap()->get());
     // 1395 is a leap year
     $this->assertEquals(true, Datium::create(2016, 6, 13, 0, 0, 0)->to('jalali')->leap()->get());
     //
     // // 1396 is not a leap year
     $this->assertEquals(false, Datium::create(2017, 3, 21, 0, 0, 0)->to('jalali')->leap()->get());
     //
     // // 1397 is not a leap year
     $this->assertEquals(false, Datium::create(2018, 3, 21, 0, 0, 0)->to('jalali')->leap()->get());
     //
     // // 1398 is not a leap year
     $this->assertEquals(false, Datium::create(2019, 3, 21, 0, 0, 0)->to('jalali')->leap()->get());
     //
     // // 1399 is a leap year
     $this->assertEquals(true, Datium::create(2020, 3, 20, 0, 0, 0)->to('jalali')->leap()->get());
 }
コード例 #2
0
ファイル: SimpleDiffTest.php プロジェクト: opencafe/datium
 public function testSimpleDiff()
 {
     $this->assertEquals('just now', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 second')->object())->simple->get());
     $this->assertEquals('just now', Datium::diff(Datium::now()->object(), Datium::now()->add('1 second')->object())->simple->get());
     $this->assertEquals('59 seconds ago', Datium::diff(Datium::now()->object(), Datium::now()->add('59 second')->object())->simple->get());
     $this->assertEquals('59 seconds remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('59 second')->object())->simple->get());
     $this->assertEquals('one minute ago', Datium::diff(Datium::now()->object(), Datium::now()->add('1 minute')->object())->simple->get());
     $this->assertEquals('one minute remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 minute')->object())->simple->get());
     $this->assertEquals('one minute ago', Datium::diff(Datium::now()->object(), Datium::now()->add('1 minute')->add('1 second')->object())->simple->get());
     $this->assertEquals('one minute remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 minute')->sub('1 second')->object())->simple->get());
     $this->assertEquals('59 minutes ago', Datium::diff(Datium::now()->object(), Datium::now()->add('59 minute')->add('1 second')->object())->simple->get());
     $this->assertEquals('59 minutes remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('59 minute')->sub('1 second')->object())->simple->get());
     $this->assertEquals('59 minutes ago', Datium::diff(Datium::now()->object(), Datium::now()->add('59 minute')->add('1 second')->object())->simple->get());
     $this->assertEquals('59 minutes remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('59 minute')->sub('1 second')->object())->simple->get());
     $this->assertEquals('an hour ago', Datium::diff(Datium::now()->object(), Datium::now()->add('1 hour')->add('1 minute')->object())->simple->get());
     $this->assertEquals('an hour remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 hour')->sub('1 minute')->object())->simple->get());
     $this->assertEquals('10 hours ago', Datium::diff(Datium::now()->object(), Datium::now()->add('10 hour')->object())->simple->get());
     $this->assertEquals('10 hours remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('10 hour')->object())->simple->get());
     $this->assertEquals('one day ago', Datium::diff(Datium::now()->object(), Datium::now()->add('1 day')->object())->simple->get());
     $this->assertEquals('one day remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 day')->object())->simple->get());
     $this->assertEquals('3 days ago', Datium::diff(Datium::now()->object(), Datium::now()->add('3 day')->object())->simple->get());
     $this->assertEquals('3 days remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('3 day')->object())->simple->get());
     $this->assertEquals('a month ago', Datium::diff(Datium::now()->object(), Datium::now()->add('1 month')->object())->simple->get());
     $this->assertEquals('a month remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 month')->object())->simple->get());
     $this->assertEquals('2 months ago', Datium::diff(Datium::now()->object(), Datium::now()->add('2 month')->add('1 day')->object())->simple->get());
     $this->assertEquals('2 months remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('2 month')->sub('1 day')->object())->simple->get());
     $this->assertEquals('one year ago', Datium::diff(Datium::now()->object(), Datium::now()->add('1 month')->add('1 year')->object())->simple->get());
     $this->assertEquals('one year remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 month')->sub('1 year')->object())->simple->get());
     $this->assertEquals('2 years ago', Datium::diff(Datium::now()->object(), Datium::now()->add('1 month')->add('2 year')->object())->simple->get());
     $this->assertEquals('2 years remaining', Datium::diff(Datium::now()->object(), Datium::now()->sub('1 month')->sub('2 year')->object())->simple->get());
 }
コード例 #3
0
ファイル: DayOfTest.php プロジェクト: opencafe/datium
 public function testLastDayOfMonth()
 {
     // leap year
     $this->assertEquals(29, Datium::create(2016, 2, 1)->dayOf()->lastDayMonth());
     $this->assertEquals(31, Datium::create(2015, 1, 1)->dayOf()->lastDayMonth());
     $this->assertEquals(30, Datium::create(2015, 1, 1)->to('hijri')->dayOf()->lastDayMonth());
     $this->assertEquals(30, Datium::create(2015, 1, 1)->to('jalali')->dayOf()->lastDayMonth());
 }
コード例 #4
0
ファイル: Hijri.php プロジェクト: opencafe/datium
<?php

use OpenCafe\Datium;
use OpenCafe\Tools\Leap;
return array('convert_to' => function ($date_time) {
    $config = (include 'Jalali.php');
    $date_time = Datium::create($date_time)->to('jalali')->object();
    $year = $date_time->format('Y');
    $month = $date_time->format('n');
    $day = $date_time->format('d');
    $temp_day = 0;
    for ($i = 1; $i < $month; $i++) {
        $temp_day += $config['month_days_number'][$i];
    }
    $temp_day += $day;
    $leap = new Leap($year);
    if ($leap->get() && $month > 11) {
        $temp_day++;
    }
    $_year = (($year - 1) * 365.2422 + $temp_day - 119) / 354.367 + 1;
    $_year = explode('.', $_year);
    $year = $_year[0];
    $_month = $_year[1];
    $var_temp = '0.0';
    for ($i = strlen($_month); $i > 2; $i--) {
        $var_temp .= '0';
    }
    $var_temp .= '1';
    $_month = $_month * $var_temp;
    $_month = $_month * 12 + 1;
    $_month = explode('.', $_month);
コード例 #5
0
ファイル: ConvertTest.php プロジェクト: opencafe/datium
 public function testHijriToJalali()
 {
     $date = Datium::create(1437, 9, 7)->from('hijri')->to('jalali')->get();
     $this->assertEquals('1395-03-24 00:00:00', $date);
 }
コード例 #6
0
ファイル: DatiumTest.php プロジェクト: opencafe/datium
 public function testGregorianCalendar()
 {
     $gregorian = Datium::create(2016, 6, 25, 12, 0, 0)->get('l jS F Y h:i:s A');
     $this->assertEquals('Saturday 25th June 2016 12:00:00 PM', $gregorian);
 }