Skip to content

Commit

Permalink
Merge pull request #8338 from kenjis/docs-time-sample-code
Browse files Browse the repository at this point in the history
docs: fix Time
  • Loading branch information
kenjis authored Dec 16, 2023
2 parents fc17a53 + 73053d3 commit 82d35c8
Show file tree
Hide file tree
Showing 35 changed files with 97 additions and 25 deletions.
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/002.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$myTime = new Time('now', 'America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/003.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$myTime = Time::now('America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/004.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$myTime = Time::parse('next Tuesday', 'America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/005.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$myTime = Time::today('America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/006.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$myTime = Time::yesterday('America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/007.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$myTime = Time::tomorrow('America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/008.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$today = Time::createFromDate(); // Uses current year, month, and day
$anniversary = Time::createFromDate(2018); // Uses current month and day
$date = Time::createFromDate(2018, 3, 15, 'America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/009.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$lunch = Time::createFromTime(11, 30); // 11:30 am today
$dinner = Time::createFromTime(18, 00, 00); // 6:00 pm today
$time = Time::createFromTime($hour, $minutes, $seconds, $timezone, $locale);
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/010.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::create($year, $month, $day, $hour, $minutes, $seconds, $timezone, $locale);
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/011.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::createFromFormat('j-M-Y', '15-Feb-2009', 'America/Chicago');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/012.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::createFromTimestamp(1501821586, 'America/Chicago', 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/013.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use CodeIgniter\I18n\Time;

$dt = new DateTime('now');
$time = Time::createFromInstance($dt, 'en_US');
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/014.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

use CodeIgniter\I18n\Time;

$datetime = Time::toDateTime();
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/015.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

// Locale: en
$time = Time::parse('March 9, 2016 12:00:00', 'America/Chicago');
echo $time->toLocalizedString('MMM d, yyyy'); // March 9, 2016
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/016.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

// Locale: en
$time = Time::parse('March 9, 2016 12:00:00', 'America/Chicago');
echo $time->toDateTimeString(); // 2016-03-09 12:00:00
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/017.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

// Locale: en
$time = Time::parse('March 9, 2016 12:00:00', 'America/Chicago');
echo $time->toDateString(); // 2016-03-09
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/018.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

// Locale: en
$time = Time::parse('March 9, 2016 12:00:00', 'America/Chicago');
echo $time->toTimeString(); // 12:00:00
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/019.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

// Assume current time is: March 10, 2017 (America/Chicago)
$time = Time::parse('March 9, 2016 12:00:00', 'America/Chicago');

Expand Down
27 changes: 15 additions & 12 deletions user_guide_src/source/libraries/time/020.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::parse('August 12, 2016 4:15:23pm');

echo $time->getYear(); // 2016
echo $time->getMonth(); // 8
echo $time->getDay(); // 12
echo $time->getHour(); // 16
echo $time->getMinute(); // 15
echo $time->getSecond(); // 23
// The output may vary based on locale.
echo $time->getYear(); // '2016'
echo $time->getMonth(); // '8'
echo $time->getDay(); // '12'
echo $time->getHour(); // '16'
echo $time->getMinute(); // '15'
echo $time->getSecond(); // '23'

echo $time->year; // 2016
echo $time->month; // 8
echo $time->day; // 12
echo $time->hour; // 16
echo $time->minute; // 15
echo $time->second; // 23
echo $time->year; // '2016'
echo $time->month; // '8'
echo $time->day; // '12'
echo $time->hour; // '16'
echo $time->minute; // '15'
echo $time->second; // '23'
25 changes: 14 additions & 11 deletions user_guide_src/source/libraries/time/021.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::parse('August 12, 2016 4:15:23pm');

echo $time->getDayOfWeek(); // 6 - but may vary based on locale's starting day of the week
echo $time->getDayOfYear(); // 225
echo $time->getWeekOfMonth(); // 2
echo $time->getWeekOfYear(); // 33
echo $time->getTimestamp(); // 1471018523 - UNIX timestamp
echo $time->getQuarter(); // 3
// The output may vary based on locale.
echo $time->getDayOfWeek(); // '6'
echo $time->getDayOfYear(); // '225'
echo $time->getWeekOfMonth(); // '2'
echo $time->getWeekOfYear(); // '33'
echo $time->getTimestamp(); // 1471018523 - UNIX timestamp (locale independent)
echo $time->getQuarter(); // '3'

echo $time->dayOfWeek; // 6
echo $time->dayOfYear; // 225
echo $time->weekOfMonth; // 2
echo $time->weekOfYear; // 33
echo $time->dayOfWeek; // '6'
echo $time->dayOfYear; // '225'
echo $time->weekOfMonth; // '2'
echo $time->weekOfYear; // '33'
echo $time->timestamp; // 1471018523
echo $time->quarter; // 3
echo $time->quarter; // '3'
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/022.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::parse('5 years ago');

echo $time->getAge(); // 5
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/023.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use CodeIgniter\I18n\Time;

echo Time::createFromDate(2012, 1, 1)->getDst(); // false
echo Time::createFromDate(2012, 9, 1)->dst; // true
6 changes: 4 additions & 2 deletions user_guide_src/source/libraries/time/024.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

echo Time::now()->getLocal(); // true
echo Time::now('Europe/London'); // false
use CodeIgniter\I18n\Time;

echo Time::now()->getLocal(); // true
echo Time::now('Europe/London')->local; // false
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/025.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use CodeIgniter\I18n\Time;

echo Time::now('America/Chicago')->getUtc(); // false
echo Time::now('UTC')->utc; // true
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/026.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$tz = Time::now()->getTimezone();
$tz = Time::now()->timezone;

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/027.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use CodeIgniter\I18n\Time;

echo Time::now('America/Chicago')->getTimezoneName(); // America/Chicago
echo Time::now('Europe/London')->timezoneName; // Europe/London
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/029.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::parse('13 May 2020 10:00', 'America/Chicago');
$time2 = $time->setTimezone('Europe/London'); // Returns new instance converted to new timezone

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/030.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::parse('May 10, 2017', 'America/Chicago');
$time2 = $time->setTimestamp(strtotime('April 1, 2017'));

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/032.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time1 = Time::parse('January 10, 2017 21:50:00', 'America/Chicago');
$time2 = Time::parse('January 11, 2017 03:50:00', 'Europe/London');

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/034.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time1 = Time::parse('January 10, 2017 21:50:00', 'America/Chicago');
$time2 = Time::parse('January 11, 2017 03:50:00', 'Europe/London');

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/035.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time1 = Time::parse('January 10, 2017 21:50:00', 'America/Chicago');
$time2 = Time::parse('January 11, 2017 03:50:00', 'America/Chicago');

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/037.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time1 = Time::parse('January 10, 2017 21:50:00', 'America/Chicago');
$time2 = Time::parse('January 11, 2017 03:50:00', 'America/Chicago');

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/038.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$time = Time::parse('March 10, 2017', 'America/Chicago');

$diff = $time->difference(Time::now());
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/039.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$current = Time::parse('March 10, 2017', 'America/Chicago');
$test = Time::parse('March 10, 2010', 'America/Chicago');

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/time/041.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\I18n\Time;

$current = Time::parse('March 10, 2017', 'America/Chicago');
$test = Time::parse('March 9, 2016 12:00:00', 'America/Chicago');

Expand Down

0 comments on commit 82d35c8

Please sign in to comment.