Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sibidharan/api-development-course-apr-2021
  • krithikramraja/api-development-course-apr-2021
  • monish-palanikumar/api-development-course-apr-2021
  • Pranesh/api-development-course-apr-2021
  • ganesha005/api-development-course-apr-2021
  • selva1011/api-development-course-apr-2021
  • hema/api-development-course-apr-2021
  • Kartheeekn/api-development-course-apr-2021
  • GopiKrishnan/api-development-course-apr-2021
  • Mhd_khalid/api-development-course-apr-2021
  • sibivarma/api-development-course-apr-2021
  • ramanajsr1/api-development-course-apr-2021
  • rahulprem2k2910/api-development-course-apr-2021
  • sabarinathanfb/api-development-course-apr-2021
  • hariharanrd/api-development-course-apr-2021
  • Akram24/api-development-course-apr-2021
  • At_muthu__/api-development-course-apr-2021
  • rii/api-development-course-apr-2021
  • harishvarmaj7/api-development-course-apr-2021
  • moovendhan/rest-api
  • k3XD16/api-development-course-apr-2021
  • vimal/api-development-course-apr-2021
  • shiva007/api-development-course-apr-2021
  • Amudhan/api-development-course-apr-2021
  • abinayacyber604/api-development-course-apr-2021
  • subash_19/api
  • Saransaran/api-development-course-apr-2021
27 results
Show changes
Showing
with 12073 additions and 0 deletions
# Carbon
[![Latest Stable Version](https://img.shields.io/packagist/v/nesbot/carbon.svg?style=flat-square)](https://packagist.org/packages/nesbot/carbon)
[![Total Downloads](https://img.shields.io/packagist/dt/nesbot/carbon.svg?style=flat-square)](https://packagist.org/packages/nesbot/carbon)
[![GitHub Actions](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fbriannesbitt%2FCarbon%2Fbadge&style=flat-square&label=Build&logo=none)](https://actions-badge.atrox.dev/briannesbitt/Carbon/goto)
[![StyleCI](https://github.styleci.io/repos/5724990/shield?style=flat-square)](https://github.styleci.io/repos/5724990)
[![codecov.io](https://img.shields.io/codecov/c/github/briannesbitt/Carbon.svg?style=flat-square)](https://codecov.io/github/briannesbitt/Carbon?branch=master)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true&style=flat-square)](https://github.com/phpstan/phpstan)
[![Tidelift](https://tidelift.com/badges/github/briannesbitt/Carbon)](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme)
An international PHP extension for DateTime. [http://carbon.nesbot.com](http://carbon.nesbot.com)
```php
<?php
use Carbon\Carbon;
printf("Right now is %s", Carbon::now()->toDateTimeString());
printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver')); //implicit __toString()
$tomorrow = Carbon::now()->addDay();
$lastWeek = Carbon::now()->subWeek();
$nextSummerOlympics = Carbon::createFromDate(2016)->addYears(4);
$officialDate = Carbon::now()->toRfc2822String();
$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;
$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');
$internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT');
// Don't really want this to happen so mock now
Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
// comparisons are always done in UTC
if (Carbon::now()->gte($internetWillBlowUpOn)) {
die();
}
// Phew! Return to normal behaviour
Carbon::setTestNow();
if (Carbon::now()->isWeekend()) {
echo 'Party!';
}
// Over 200 languages (and over 500 regional variants) supported:
echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
echo Carbon::now()->subMinutes(2)->locale('zh_CN')->diffForHumans(); // '2分钟前'
echo Carbon::parse('2019-07-23 14:51')->isoFormat('LLLL'); // 'Tuesday, July 23, 2019 2:51 PM'
echo Carbon::parse('2019-07-23 14:51')->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51'
// ... but also does 'from now', 'after' and 'before'
// rolling up to seconds, minutes, hours, days, months, years
$daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();
```
[Get supported nesbot/carbon with the Tidelift Subscription](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme)
## Installation
### With Composer
```
$ composer require nesbot/carbon
```
```json
{
"require": {
"nesbot/carbon": "^2.16"
}
}
```
```php
<?php
require 'vendor/autoload.php';
use Carbon\Carbon;
printf("Now: %s", Carbon::now());
```
### Without Composer
Why are you not using [composer](http://getcomposer.org/)? Download the Carbon [latest release](https://github.com/briannesbitt/Carbon/releases) and put the contents of the ZIP archive into a directory in your project. Then require the file `autoload.php` to get all classes and dependencies loaded on need.
```php
<?php
require 'path-to-Carbon-directory/autoload.php';
use Carbon\Carbon;
printf("Now: %s", Carbon::now());
```
## Docs
[http://carbon.nesbot.com/docs](http://carbon.nesbot.com/docs)
## Security contact information
To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.
## Credits
### Contributors
This project exists thanks to all the people who contribute.
<a href="https://github.com/briannesbitt/Carbon/graphs/contributors" target="_blank"><img src="https://opencollective.com/Carbon/contributors.svg?width=890&button=false" /></a>
### Translators
[Thanks to people helping us to translate Carbon in so many languages](https://carbon.nesbot.com/contribute/translators/)
### Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/Carbon#backer)]
<a href="https://opencollective.com/Carbon#backers" target="_blank"><img src="https://opencollective.com/Carbon/backers.svg?width=890"></a>
### Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/Carbon#sponsor)]
<a href="https://opencollective.com/Carbon/sponsor/0/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/Carbon/sponsor/1/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/Carbon/sponsor/2/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/Carbon/sponsor/3/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/Carbon/sponsor/4/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/4/avatar.svg"></a>
## Carbon for enterprise
Available as part of the Tidelift Subscription.
The maintainers of ``Carbon`` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
This diff is collapsed.
<?php
/**
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <brian@nesbot.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Carbon;
use DateTimeInterface;
interface CarbonConverterInterface
{
public function convertDate(DateTimeInterface $dateTime, bool $negated = false): CarbonInterface;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/**
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <brian@nesbot.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Carbon;
use Carbon\Exceptions\InvalidCastException;
use Carbon\Exceptions\InvalidTimeZoneException;
use DateTimeInterface;
use DateTimeZone;
class CarbonTimeZone extends DateTimeZone
{
public function __construct($timezone = null)
{
parent::__construct(static::getDateTimeZoneNameFromMixed($timezone));
}
protected static function parseNumericTimezone($timezone)
{
if ($timezone <= -100 || $timezone >= 100) {
throw new InvalidTimeZoneException('Absolute timezone offset cannot be greater than 100.');
}
return ($timezone >= 0 ? '+' : '').$timezone.':00';
}
protected static function getDateTimeZoneNameFromMixed($timezone)
{
if (\is_null($timezone)) {
return date_default_timezone_get();
}
if (\is_string($timezone)) {
$timezone = preg_replace('/^\s*([+-]\d+)(\d{2})\s*$/', '$1:$2', $timezone);
}
if (is_numeric($timezone)) {
return static::parseNumericTimezone($timezone);
}
return $timezone;
}
protected static function getDateTimeZoneFromName(&$name)
{
return @timezone_open($name = (string) static::getDateTimeZoneNameFromMixed($name));
}
/**
* Cast the current instance into the given class.
*
* @param string $className The $className::instance() method will be called to cast the current object.
*
* @return DateTimeZone
*/
public function cast(string $className)
{
if (!method_exists($className, 'instance')) {
if (is_a($className, DateTimeZone::class, true)) {
return new $className($this->getName());
}
throw new InvalidCastException("$className has not the instance() method needed to cast the date.");
}
return $className::instance($this);
}
/**
* Create a CarbonTimeZone from mixed input.
*
* @param DateTimeZone|string|int|null $object original value to get CarbonTimeZone from it.
* @param DateTimeZone|string|int|null $objectDump dump of the object for error messages.
*
* @throws InvalidTimeZoneException
*
* @return false|static
*/
public static function instance($object = null, $objectDump = null)
{
$tz = $object;
if ($tz instanceof static) {
return $tz;
}
if ($tz === null) {
return new static();
}
if (!$tz instanceof DateTimeZone) {
$tz = static::getDateTimeZoneFromName($object);
}
if ($tz === false) {
if (Carbon::isStrictModeEnabled()) {
throw new InvalidTimeZoneException('Unknown or bad timezone ('.($objectDump ?: $object).')');
}
return false;
}
return new static($tz->getName());
}
/**
* Returns abbreviated name of the current timezone according to DST setting.
*
* @param bool $dst
*
* @return string
*/
public function getAbbreviatedName($dst = false)
{
$name = $this->getName();
foreach ($this->listAbbreviations() as $abbreviation => $zones) {
foreach ($zones as $zone) {
if ($zone['timezone_id'] === $name && $zone['dst'] == $dst) {
return $abbreviation;
}
}
}
return 'unknown';
}
/**
* @alias getAbbreviatedName
*
* Returns abbreviated name of the current timezone according to DST setting.
*
* @param bool $dst
*
* @return string
*/
public function getAbbr($dst = false)
{
return $this->getAbbreviatedName($dst);
}
/**
* Get the offset as string "sHH:MM" (such as "+00:00" or "-12:30").
*
* @param DateTimeInterface|null $date
*
* @return string
*/
public function toOffsetName(DateTimeInterface $date = null)
{
return static::getOffsetNameFromMinuteOffset(
$this->getOffset($date ?: Carbon::now($this)) / 60
);
}
/**
* Returns a new CarbonTimeZone object using the offset string instead of region string.
*
* @param DateTimeInterface|null $date
*
* @return CarbonTimeZone
*/
public function toOffsetTimeZone(DateTimeInterface $date = null)
{
return new static($this->toOffsetName($date));
}
/**
* Returns the first region string (such as "America/Toronto") that matches the current timezone or
* false if no match is found.
*
* @see timezone_name_from_abbr native PHP function.
*
* @param DateTimeInterface|null $date
* @param int $isDst
*
* @return string|false
*/
public function toRegionName(DateTimeInterface $date = null, $isDst = 1)
{
$name = $this->getName();
$firstChar = substr($name, 0, 1);
if ($firstChar !== '+' && $firstChar !== '-') {
return $name;
}
$date = $date ?: Carbon::now($this);
// Integer construction no longer supported since PHP 8
// @codeCoverageIgnoreStart
try {
$offset = @$this->getOffset($date) ?: 0;
} catch (\Throwable $e) {
$offset = 0;
}
// @codeCoverageIgnoreEnd
$name = @timezone_name_from_abbr('', $offset, $isDst);
if ($name) {
return $name;
}
foreach (timezone_identifiers_list() as $timezone) {
if (Carbon::instance($date)->tz($timezone)->getOffset() === $offset) {
return $timezone;
}
}
return false;
}
/**
* Returns a new CarbonTimeZone object using the region string instead of offset string.
*
* @param DateTimeInterface|null $date
*
* @return CarbonTimeZone|false
*/
public function toRegionTimeZone(DateTimeInterface $date = null)
{
$tz = $this->toRegionName($date);
if ($tz === false) {
if (Carbon::isStrictModeEnabled()) {
throw new InvalidTimeZoneException('Unknown timezone for offset '.$this->getOffset($date ?: Carbon::now($this)).' seconds.');
}
return false;
}
return new static($tz);
}
/**
* Cast to string (get timezone name).
*
* @return string
*/
public function __toString()
{
return $this->getName();
}
/**
* Create a CarbonTimeZone from mixed input.
*
* @param DateTimeZone|string|int|null $object
*
* @return false|static
*/
public static function create($object = null)
{
return static::instance($object);
}
/**
* Create a CarbonTimeZone from int/float hour offset.
*
* @param float $hourOffset number of hour of the timezone shift (can be decimal).
*
* @return false|static
*/
public static function createFromHourOffset(float $hourOffset)
{
return static::createFromMinuteOffset($hourOffset * Carbon::MINUTES_PER_HOUR);
}
/**
* Create a CarbonTimeZone from int/float minute offset.
*
* @param float $minuteOffset number of total minutes of the timezone shift.
*
* @return false|static
*/
public static function createFromMinuteOffset(float $minuteOffset)
{
return static::instance(static::getOffsetNameFromMinuteOffset($minuteOffset));
}
/**
* Convert a total minutes offset into a standardized timezone offset string.
*
* @param float $minutes number of total minutes of the timezone shift.
*
* @return string
*/
public static function getOffsetNameFromMinuteOffset(float $minutes): string
{
$minutes = round($minutes);
$unsignedMinutes = abs($minutes);
return ($minutes < 0 ? '-' : '+').
str_pad((string) floor($unsignedMinutes / 60), 2, '0', STR_PAD_LEFT).
':'.
str_pad((string) ($unsignedMinutes % 60), 2, '0', STR_PAD_LEFT);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.