https://github.com/leafsphp/date
ð
Leaf PHP date/time module
https://github.com/leafsphp/date
date leafphp php
Last synced: about 2 months ago
JSON representation
ð Leaf PHP date/time module
- Host: GitHub
- URL: https://github.com/leafsphp/date
- Owner: leafsphp
- Created: 2021-09-19T14:40:54.000Z (over 3 years ago)
- Default Branch: v4.x
- Last Pushed: 2025-03-31T13:10:11.000Z (2 months ago)
- Last Synced: 2025-04-13T04:29:39.890Z (about 2 months ago)
- Topics: date, leafphp, php
- Language: PHP
- Homepage: https://leafphp.dev/docs/utils/date.html
- Size: 60.5 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
![]()
â° Tick
A powerful, elegant date/time manipulation library for PHP with a familiar JavaScript-like API
## ð Why Tick?
**Tick** is a modern, lightweight PHP date/time library designed to make working with dates and times as painless as possible. If you're familiar with JavaScript libraries like Moment.js or Day.js, you'll feel right at home with Tick.
```php
// Get current date in a specific format
echo tick()->format('MMMM Do, YYYY'); // March 31st, 2025// Chain methods for complex operations
$nextFriday = tick()->add(1, 'week')->startOf('week')->add(4, 'day');
echo $nextFriday->format('dddd, MMMM D'); // Friday, April 11
```## ð Installation
**Using [Leaf CLI](https://cli.leafphp.dev) (Recommended)**:
```bash
leaf install date
```**Using [Composer](https://getcomposer.org/)**:
```bash
composer require leafs/date
```## ð Quick Start
```php
// Current date and time
echo tick()->now(); // 2025-03-31T12:29:29+00:00// Parse a specific date
$birthday = tick('1990-05-15');
echo $birthday->format('MMMM D, YYYY'); // May 15, 1990// Manipulate dates
$futureDate = tick()->add(3, 'months')->subtract(2, 'days');
echo $futureDate->format('YYYY-MM-DD'); // 2025-06-29
```## âĻ Features
- **ð Familiar API** - If you know Day.js or Moment.js, you already know Tick
- **ðŠķ Lightweight** - No heavy dependencies, just pure PHP goodness
- **ð Native Integration** - Seamless integration with PHP's DateTime objects
- **ð Timezone Support** - Work with dates across different timezones effortlessly
- **ð Date Comparison** - Easily compare dates with intuitive methods
- **ð§Đ Extensible** - Add your own custom functionality when needed
- **ð Validation** - Validate dates with built-in methods
- **ð Formatting** - Format dates in any way you need## ð API Reference
### Creating Dates
```php
// Current date and time
tick();
tick()->now();// From string
tick('2025-03-31');
tick('2025/03/31');
tick('March 31, 2025');// From DateTime
tick(new DateTime('2025-03-31'));// From tick object
$tomorrow = tick('2025-03-31')->add(1, 'day');
tick($tomorrow);
```### Formatting
```php
$date = tick('2025-03-31');// Standard formats
$date->format('YYYY-MM-DD'); // 2025-03-31
$date->format('MMMM D, YYYY'); // March 31, 2025
$date->format('ddd, MMM D, YYYY'); // Mon, Mar 31, 2025
$date->format('YYYY-MM-DD HH:mm:ss'); // 2025-03-31 12:29:29// Predefined formats
$date->toDateString(); // 2025-03-31
$date->toTimeString(); // 12:29:29
$date->toDateTimeString(); // 2025-03-31 12:29:29
$date->toISOString(); // 2025-03-31T12:29:29.000Z
```### Manipulating Dates
```php
$date = tick('2025-03-31');// Add time
$date->add(1, 'day'); // 2025-04-01
$date->add(2, 'months'); // 2025-05-31
$date->add(1, 'year'); // 2026-03-31// Subtract time
$date->subtract(1, 'week'); // 2025-03-24
$date->subtract(3, 'hours'); // 2025-03-31 09:29:29// Start/End of time units
$date->startOf('month'); // 2025-03-01 00:00:00
$date->endOf('year'); // 2025-12-31 23:59:59.999999
$date->startOf('day'); // 2025-03-31 00:00:00
```### Comparing Dates
```php
$date = tick('2025-03-31');$date->isBefore('2025-04-01'); // true
$date->isAfter('2025-03-30'); // true
$date->isSame('2025-03-31'); // true
$date->isBetween('2025-03-30', '2025-04-01'); // true
```### Working with Timezones
```php
// Create a date in a specific timezone
$tokyoTime = tick('2025-03-31', 'Asia/Tokyo');// Convert between timezones
$newYorkTime = $tokyoTime->setTimezone('America/New_York');
```## ðĪ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request---
Made with âĪïļ by Leaf PHP