danharrin/date-format-converter
Convert date/time format strings between PHP, Moment.js, ICU and more. Handy for Laravel apps that need consistent formatting across backend and frontend, with simple helpers to translate patterns and reduce duplicated format definitions.
YYYY-MM-DD ↔ MM/DD/YYYY), making it ideal for applications requiring multi-format date handling (e.g., APIs, reporting tools, or legacy system integrations). It is not a full-fledged date manipulation library (e.g., Carbon) but fills a niche for format normalization without heavy dependencies.DateFormatConverter::convert()).12-hour AM/PM with/without spaces, locale-specific formats like dd.MM.yyyy). Requires custom token mapping for unsupported cases.null, or log warnings)?TT.MM.JJJJ) needed? If so, does the package support them, or will a wrapper be required?Carbon or IntlDateFormatter suffice? Only adopt this if the package offers simpler syntax or better performance for your use case.Date facade (if wrapping for consistency).str_replace() or regex-based conversions.// config/services.php
'date_format_converter' => danharrin\DateFormatConverter\Converter::class,
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton('dateFormatConverter', function ($app) {
return new \danharrin\DateFormatConverter\Converter();
});
}
// app/Helpers/DateHelper.php
class DateHelper {
public static function convert(string $input, string $from, string $to): string
{
return app('dateFormatConverter')->convert($input, $from, $to);
}
}
// app/Http/Middleware/NormalizeDateFormats.php
public function handle($request, Closure $next) {
$request->merge([
'date_normalized' => DateHelper::convert(
$request->date,
'YYYY-MM-DD',
'MM/DD/YYYY'
)
]);
return $next($request);
}
DB::raw with converted dates).create_function).| Scenario | Impact | Mitigation |
|---|---|---|
| Invalid input format | Silent failure or incorrect output | Add input validation (e.g., regex). |
| Unsupported token | Exception or partial conversion | Extend token mappings or wrap in try-catch. |
| PHP version incompatibility | Package breaks | Pin version in composer.json. |
| Locale-specific bugs | Incorrect formatting for non-EN | Test with target locales early. |
YYYY vs. yy).try-catch for edge cases).How can I help you explore Laravel packages today?