Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Human Date Laravel Package

cocur/human-date

Transforms DateTime values into human‑readable strings like Today, Tomorrow, Yesterday, Next Tuesday, or formatted dates. Supports translated strings via a translation interface (including Symfony Translation). Lightweight, no external dependencies, PSR‑4, PHP 5.4+ and HHVM.

View on GitHub
Deep Wiki
Context7

Transforms dates into a human-readable form.

Frequently asked questions about Human Date
How do I install cocur/human-date in a Laravel project?
Run `composer require cocur/human-date` in your project root. The package works with Laravel’s Carbon dependency, so no additional setup is needed beyond enabling PHP’s `intl` extension if missing.
Does cocur/human-date support Laravel’s Eloquent models?
Yes. Add an accessor to your model (e.g., `public function getCreatedAtHumanAttribute() { return HumanDate::transform($this->created_at); }`) to format timestamps directly in Blade or API responses.
Can I use this package in Blade templates?
Absolutely. Inject the package as a helper or create a Blade directive. For example, `@php echo HumanDate::transform($order->created_at) @endphp` renders dates like '3 hours ago' in your views.
What Laravel versions does cocur/human-date support?
The package is compatible with Laravel 5.8+ (PHP 7.2+) and Laravel 10+ (PHP 8.x). Test thoroughly with your Laravel version, as the package hasn’t been updated since 2014 but relies on stable Carbon APIs.
How do I handle localization for non-English dates?
Use PHP’s `IntlDateFormatter` for basic locale support, but note pluralization rules (e.g., '1 day ago' vs. '2 days ago') may require manual adjustments. For advanced cases, combine with Laravel’s localization or `voku/portable-ascii`.
Is cocur/human-date safe for production use?
Yes, but test edge cases like timezone handling and future dates. Cache formatted dates in Blade views or API responses if rendering many timestamps to avoid performance overhead.
What if the PHP `intl` extension is disabled?
The package requires `intl`. If unavailable, implement a fallback (e.g., `Carbon::diffForHumans()` or a simple `date()` format) or enable the extension in your PHP configuration.
Can I customize the output format (e.g., 'in 2 days' vs. '2 days ago')?
The package uses `HumanDate::transform()` for past dates and `HumanDate::transformFuture()` for future dates. Override the default behavior by extending the class or using a custom translation adapter.
Are there alternatives to cocur/human-date for Laravel?
Yes. Consider `Carbon::diffForHumans()` (built into Laravel) for basic needs, or `spatie/array-to-xml` for broader transformations. For advanced localization, evaluate `voku/portable-ascii` or `symfony/intl`.
How do I test cocur/human-date in a Laravel app?
Write unit tests for critical use cases (e.g., `HumanDate::transform(now())`, `HumanDate::transform(yesterday())`). Mock the `DateTime` object to simulate edge timestamps like 'now' or future dates.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
yandex/translate-api
voku/simple_html_dom
league/flysystem-vfs
bkwld/upchuck
filament/spatie-laravel-tags-plugin
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php