|
| 1 | +--- |
| 2 | +title: Date |
| 3 | +--- |
| 4 | +<!-- |
| 5 | +Do not edit this file - Generated from https://github.com/tangibleinc/framework |
| 6 | +--> |
| 7 | +# Date |
| 8 | + |
| 9 | +Examples |
| 10 | + |
| 11 | +```php |
| 12 | +// Get interface |
| 13 | + |
| 14 | +$tdate = tangible\date(); |
| 15 | + |
| 16 | +// Set language |
| 17 | + |
| 18 | +$tdate->setLocale('fr'); |
| 19 | + |
| 20 | +$date = $tdate('3 days ago'); |
| 21 | + |
| 22 | +echo $date->ago(); // => il y a 3 jours |
| 23 | +echo $date->format('l j F Y'); // => mardi 7 avril 2020 |
| 24 | + |
| 25 | +// Create from date and time |
| 26 | + |
| 27 | +$date = $tdate('2000-01-31'); |
| 28 | +$date = $tdate->create(2000, 1, 31); |
| 29 | +$date = $tdate->create(2000, 1, 31, 12, 0, 0); |
| 30 | + |
| 31 | +// Add/subtract |
| 32 | + |
| 33 | +$yesterday = $tdate->now()->sub('1 day'); |
| 34 | +$tomorrow = $tdate->now()->add('1 day'); |
| 35 | + |
| 36 | +// Duration |
| 37 | + |
| 38 | +echo $tdate->now()->timespan( |
| 39 | + $tdate('+1000 days') |
| 40 | +); |
| 41 | +// 2 years, 8 months, 3 weeks, 5 days |
| 42 | + |
| 43 | +// Get/set date attributes |
| 44 | + |
| 45 | +$date->year = 2013; |
| 46 | +$date->month = 1; |
| 47 | +$date->day = 31; |
| 48 | + |
| 49 | +$date->hour = 12; |
| 50 | +$date->minute = 0; |
| 51 | +$date->second = 0; |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +## Updating the Carbon library |
| 56 | + |
| 57 | +Steps to update: |
| 58 | + |
| 59 | +- Download latest version of Carbon from: https://github.com/briannesbitt/Carbon/releases |
| 60 | +- Run: `composer install --no-dev` |
| 61 | + |
| 62 | + Workaround to maintain compatibility with PHP 7.4 - The dependency `symfony/translation` version 6 requires PHP 8.1, so we must manually install v5 which is still compatible with both PHP 7 and 8. |
| 63 | + |
| 64 | + ``` |
| 65 | + rm composer.lock |
| 66 | + composer require symfony/translation:5 symfony/translation-contracts:2 --ignore-platform-reqs |
| 67 | + composer install --ignore-platform-reqs --no-dev |
| 68 | + ``` |
| 69 | +
|
| 70 | +- Copy and replace folders src, vendor, lazy to ./Carbon |
| 71 | +- Run script to convert namespace, from this folder: ./namespace |
| 72 | +- Edit Carbon/vendor/composer/autoload_static.php, replace: |
| 73 | +
|
| 74 | +```php |
| 75 | +'C' => |
| 76 | +array ( |
| 77 | + 'Tangible\\Carbon\\' => 7, |
| 78 | +), |
| 79 | +``` |
| 80 | + |
| 81 | +..with.. |
| 82 | + |
| 83 | +```php |
| 84 | +'T' => |
| 85 | +array ( |
| 86 | + 'Tangible\\Carbon\\' => 16, |
| 87 | +), |
| 88 | +``` |
0 commit comments