# Dates (laravel-rust-format)

> Use laravel_rust_format_core::carbon for PHP date letters and Carbon’s English relative times. Use Jiff 1 types directly, including those re-exported by…

- Package: laravel-rust-format (Laravel for Rust, alpha), crates: `laravel-rust-format`, `laravel-rust-format-core`
- Maintenance: active; Latest release: 0.1.1 (2026-12-04); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-format), [crates.io](https://crates.io/crates/laravel-rust-format/0.1.1), [docs.rs](https://docs.rs/laravel-rust-format/0.1.1), [Changelog](https://oss.bowerbird.si/format/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/SECURITY.md)
- Based on: [Laravel Str, Number and Pluralizer](https://github.com/laravel/framework): The behaviour of Illuminate\Support\Str, Number and Pluralizer, as typed Rust functions with English defaults.; [Carbon](https://github.com/briannesbitt/Carbon): The calendar, formats and relative-time translations, on Jiff with an explicit clock instant. The generated locale tables credit the authors of each language file.; [Doctrine Inflector](https://github.com/doctrine/inflector): English inflection rules, generated into Rust tables.; [Portable ASCII](https://github.com/voku/portable-ascii): Transliteration tables for Str::ascii and Str::slug, generated into Rust tables.; [League CommonMark](https://github.com/thephpleague/commonmark): Reference behaviour for Markdown in the PHP oracle; Comrak renders Markdown in Rust.; [Ramsey UUID](https://github.com/ramsey/uuid): Reference behaviour for identifiers in the PHP oracle; the core builds them in Rust.; [Symfony UID](https://github.com/symfony/uid): Reference behaviour for identifiers in the PHP oracle; the core builds them in Rust.
- PHP parity: core (465 covered, 4 diverged, 3 planned of 472 abilities; 133,206 fixtures; follows illuminate/support 13.39.0; verified 2026-12-04)
- Used in production across multiple projects.
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/format/docs/dates/
- Source: https://github.com/bowerbird-si/laravel-rust-format/blob/16e2c1a95c60fb32c5ee2f37b7d58a9f72be23f7/docs/dates.md

Use `laravel_rust_format_core::carbon` for PHP date letters and Carbon’s English relative times. Use Jiff 1 types directly, including those re-exported by Laravel for Rust under `laravel::time`.

| Input | Meaning |
| --- | --- |
| `jiff::ZonedDateTime` | Date and time in its own zone |
| `jiff::Timestamp` | Instant displayed in UTC |
| `jiff::civil::DateTime` | Wall time interpreted in UTC |
| `jiff::civil::Date` | Midnight UTC on that date |

These types also work by reference. `CarbonInput::to_zoned_datetime` returns a `Result`. Jiff’s timestamp range is narrower than its civil range, so a civil date or time outside the UTC timestamp range returns an error. Formatting, comparisons, calendar properties and relative-time helpers propagate that error. Use a named zone when you need its name, its abbreviation or its daylight-saving rules.

## Parse dates and timestamps

```rust
use jiff::{Timestamp, tz::TimeZone};
use laravel_rust_format_core::carbon;

let paris = TimeZone::get("Europe/Paris").unwrap();
let date = carbon::parse("2024-02-29 12:45:00", &paris, Timestamp::UNIX_EPOCH).unwrap();
assert_eq!(carbon::to_date_time_string_with(&date, carbon::DateTimePrecision::Minute).unwrap(), "2024-02-29 12:45");
assert_eq!(carbon::to_iso_string_keep_offset(&date).unwrap().as_deref(), Some("2024-02-29T12:45:00.000000+01:00"));
assert_eq!(carbon::create_from_format("!Y-m", "2024-02", &paris).unwrap().day(), 1);
assert_eq!(carbon::create_from_timestamp(-0.25, &TimeZone::UTC).unwrap().subsec_nanosecond(), 750_000_000);
```

`parse` accepts PHP's free-form date grammar, including ISO week dates, English month
names, time zones and relatives like `next Friday noon`. It also accepts RFC 9557
bracketed zones. The supplied clock freezes Carbon's relative expressions.
`modify` uses its input date as the clock and preserves the receiver's zone for ordinary
modifiers. `create_from_timestamp` takes integer or float Unix seconds and rounds floats
to microseconds.

```rust
use jiff::{civil::date, tz::TimeZone};
use laravel_rust_format_core::carbon;

let base = date(2024, 1, 31).at(8, 15, 0, 0);
let friday = carbon::parse("next Friday noon", &TimeZone::UTC, base).unwrap();
assert_eq!(carbon::to_date_time_string(friday).unwrap(), "2024-02-02 12:00:00");

let rolled = carbon::modify(base, "+1 month").unwrap();
assert_eq!(carbon::to_date_time_string(rolled).unwrap(), "2024-03-02 08:15:00");
```

For PHP's constructor and Unix-seconds interfaces, see [PHP functions](https://oss.bowerbird.si/format/docs/php-functions/).
The [parity guide](https://oss.bowerbird.si/format/docs/parity/#free-form-date-grammar) lists grammar coverage and limits.

`create_from_format` reads numeric and named dates, clock fields, offsets and IANA zone names with PHP’s pattern letters. The supported letters are `d j D l S z F M m n X x Y y a A g h G H i s u v e O P p T U c`. Use `!` to reset fields parsed to that point and initialize missing fields to the epoch. Use `|` to apply epoch defaults only to unparsed fields. With an explicit clock, `create_from_format_with_now` can inherit omitted fields. Input with unconsumed trailing data returns the diagnostic `Trailing data`. The `+` modifier permits that suffix.

## PHP date letters

Pass the PHP pattern directly to `carbon::format(date, pattern)`. PHP patterns use bare letters such as `Y-m-d`. A backslash escapes the next character, a final backslash emits a NUL byte, and unrecognized characters are copied through.

```rust
use jiff::civil::date;
use laravel_rust_format_core::carbon;

assert_eq!(carbon::format(date(2027, 1, 1), r"o-\WW").unwrap(), "2026-W53");
assert_eq!(carbon::format(date(2026, 12, 3), "l jS F").unwrap(), "Thursday 3rd December");
```

The example values below use `2026-12-03T14:30:07.123456+01:00[Europe/Amsterdam]`.

| Letter | Meaning | Example |
| --- | --- | --- |
| `d` | Day of month, two digits | `03` |
| `D` | Weekday abbreviation | `Thu` |
| `j` | Day of month | `3` |
| `l` | Full weekday name | `Thursday` |
| `N` | ISO weekday, Monday = 1 | `4` |
| `S` | English ordinal suffix | `rd` |
| `w` | Weekday number, Sunday = 0 | `4` |
| `z` | Day of year, January 1 = 0 | `336` |
| `W` | ISO week number, two digits | `49` |
| `F` | Full month name | `December` |
| `m` | Month number, two digits | `12` |
| `M` | Month abbreviation | `Dec` |
| `n` | Month number | `12` |
| `t` | Number of days in the month | `31` |
| `L` | Leap year flag | `0` |
| `o` | ISO week-numbering year | `2026` |
| `X` | Year with an explicit sign | `+2026` |
| `x` | Year with a sign when expansion requires it | `2026` |
| `Y` | Year, at least four digits | `2026` |
| `y` | Two-digit year | `26` |
| `a` | Lowercase meridiem | `pm` |
| `A` | Uppercase meridiem | `PM` |
| `B` | Swatch Internet Time in whole beats | `604` |
| `g` | Hour on a 12-hour clock | `2` |
| `G` | Hour on a 24-hour clock | `14` |
| `h` | Hour on a 12-hour clock, two digits | `02` |
| `H` | Hour on a 24-hour clock, two digits | `14` |
| `i` | Minute, two digits | `30` |
| `s` | Second, two digits | `07` |
| `u` | Fractional second in microseconds, six digits | `123456` |
| `v` | Fractional second in milliseconds, three digits | `123` |
| `e` | Time zone identifier | `Europe/Amsterdam` |
| `I` | Time zone daylight saving flag | `0` |
| `O` | UTC offset without a colon | `+0100` |
| `P` | UTC offset with a colon | `+01:00` |
| `p` | Colonized offset, with `Z` for UTC | `+01:00` |
| `T` | Time zone abbreviation | `CET` |
| `Z` | Offset in seconds east of UTC | `3600` |
| `c` | ISO 8601 date and time | `2026-12-03T14:30:07+01:00` |
| `r` | RFC 2822 date and time | `Thu, 03 Dec 2026 14:30:07 +0100` |
| `U` | Whole Unix seconds, rounded down | `1796304607` |

## Carbon string conversions

The helpers below use the same Amsterdam input. They return `Result<String>`. The exception is `to_iso_string`, which returns `Result<Option<String>>` and uses `Ok(None)` for local year zero. `to_iso_string` converts to UTC. The other helpers keep the input zone.

| Carbon method | Rust helper | Output |
| --- | --- | --- |
| `toIso8601String()` | `to_iso8601_string` | `2026-12-03T14:30:07+01:00` |
| `toISOString()` | `to_iso_string` | `2026-12-03T13:30:07.123456Z` |
| `toDateString()` | `to_date_string` | `2026-12-03` |
| `toTimeString()` | `to_time_string` | `14:30:07` |
| `toDateTimeString()` | `to_date_time_string` | `2026-12-03 14:30:07` |
| `toAtomString()` | `to_atom_string` | `2026-12-03T14:30:07+01:00` |
| `toRfc2822String()` | `to_rfc2822_string` | `Thu, 03 Dec 2026 14:30:07 +0100` |
| `toFormattedDateString()` | `to_formatted_date_string` | `Dec 3, 2026` |
| `toDayDateTimeString()` | `to_day_date_time_string` | `Thu, Dec 3, 2026 2:30 PM` |
| `toCookieString()` | `to_cookie_string` | `Thursday, 03-Dec-2026 14:30:07 CET` |
| `toRssString()` | `to_rss_string` | `Thu, 03 Dec 2026 14:30:07 +0100` |
| `toW3cString()` | `to_w3c_string` | `2026-12-03T14:30:07+01:00` |

For a different fractional precision, use `format` with `u` for microseconds or `v` for milliseconds. Both truncate extra digits.

## Relative time with `diff_for_humans`

The core always takes a comparison instant. Use `Relative::Now(now)` for the omitted PHP argument, or `Relative::To(&other)` when the PHP call passed a date. The interval is calendar-aware and is calculated in the subject’s zone. The default displays one part, down to seconds.

```rust
use laravel_rust_format_core::carbon::{DiffForHumans, Relative, diff_for_humans};

let now: jiff::ZonedDateTime = "2026-12-03T14:30:00+00:00[UTC]".parse().unwrap();
let date = jiff::civil::date(2026, 12, 3).at(12, 0, 0, 0);
assert_eq!(diff_for_humans(date, Relative::To(&now)).unwrap(), "2 hours before");
assert_eq!(diff_for_humans(date, Relative::Now(now.clone())).unwrap(), "2 hours ago");
assert_eq!(
    DiffForHumans::new().parts(2).join().apply(date, Relative::Now(now)).unwrap(),
    "2 hours and 30 minutes ago",
);
```

The comparison instant and the wording are independent. Set the wording with `syntax`.

| Carbon syntax | Rust | Wording |
| --- | --- | --- |
| Auto (0) | `DiffSyntax::Auto` | Clock wording for `Now`, comparison wording for `To` |
| Absolute (1) | `DiffSyntax::Absolute` or `.absolute()` | Quantity and unit |
| Relative to now (2) | `DiffSyntax::RelativeToNow` | `ago` or `from now` |
| Relative to other (3) | `DiffSyntax::RelativeToOther` | `before` or `after` |

| Carbon option | Builder method | Effect |
| --- | --- | --- |
| `short` | `.short()` | Compact unit labels |
| `parts` | `.parts(n)` | Maximum part count. Use `-1` for all parts as in Carbon’s options array. |
| `join` | `.join()`, `.join_with(glue)`, `.join_with_last(glue, last)`, `.join_using(&callback)` | English conjunction, custom separators, or a Rust callback. The default is space-separated. |
| `aUnit` | `.a_unit()` | Uses English articles for singular units where Carbon does. |
| `minimumUnit` | `.minimum_unit(unit)` | Sets the smallest displayed unit and the unit used for an empty difference. |
| `skip` | `.skip(&units)` | Skips selected units using their names, plurals or shortcuts. |

`options(mask)` replaces the flag mask. These methods set individual flags.

| Flag | Builder method | Effect |
| --- | --- | --- |
| `NO_ZERO_DIFF` (1) | `.no_zero_diff()` | Uses one unit for an empty difference. |
| `JUST_NOW` (2) | `.just_now()` | Uses `just now` for an empty clock-relative difference. |
| `ONE_DAY_WORDS` (4) | `.one_day_words()` | Uses `yesterday` or `tomorrow` in long, single-part clock wording. |
| `TWO_DAY_WORDS` (8) | `.two_day_words()` | Uses `before yesterday` or `after tomorrow` in long, single-part clock wording. |
| `SEQUENTIAL_PARTS_ONLY` (16) | `.sequential_parts_only()` | Stops after the first missing unit once output has begun. |
| `ROUND` (32) | `.round()` | Rounds excess parts to the nearest, with ties up. |
| `FLOOR` (64) | `.floor()` | Rounds down on Carbon’s reference calendar. |
| `CEIL` (128) | `.ceil()` | Rounds excess parts up. |

When multiple rounding flags are set, `ROUND` takes precedence, then `CEIL`, then `FLOOR`. Rounding uses the full interval before the display cutoff, including fractional seconds. [Known time zone differences](https://oss.bowerbird.si/format/docs/parity/#dates)

## Calendar arithmetic and comparisons

Calendar functions live in `laravel_rust_format_core::carbon` and accept any `CarbonInput`. Pass a Jiff `ZonedDateTime` when the zone matters. Civil dates and timestamps are interpreted in UTC. Pass dates by reference to keep using the originals.

```rust
use jiff::civil::date;
use laravel_rust_format_core::carbon::{add_months, add_months_no_overflow, end_of_month};

let jan_31 = date(2024, 1, 31);
assert_eq!(add_months(jan_31, 1).unwrap().date(), date(2024, 3, 2));
assert_eq!(add_months_no_overflow(jan_31, 1).unwrap().date(), date(2024, 2, 29));
assert_eq!(
    end_of_month(date(2024, 2, 1)).unwrap().datetime().to_string(),
    "2024-02-29T23:59:59.999999",
);
```

Whole calendar days normally preserve the local time on the clock. Hours represent elapsed time, so 24 hours can land at a different local time. Fractional days apply the whole calendar days first, then add the fractional remainder as elapsed time.

```rust
use jiff::ZonedDateTime;
use laravel_rust_format_core::carbon::{
    DifferenceOptions, add_days, add_hours, diff_in_days, diff_in_days_with, is_tomorrow,
};

let now: ZonedDateTime = "2024-03-10T00:00:00-05:00[America/New_York]".parse().unwrap();
let tomorrow = add_days(&now, 1).unwrap();
assert_eq!(tomorrow.hour(), 0);
assert_eq!(add_hours(&now, 24).unwrap().hour(), 1);
assert!(is_tomorrow(&tomorrow, &now).unwrap());
assert_eq!(diff_in_days(&tomorrow, &now).unwrap(), -1.0);
assert_eq!(
    diff_in_days_with(&now, &tomorrow, DifferenceOptions::default().utc(true)).unwrap(),
    23.0 / 24.0,
);
```

Use a `CalendarUnit` to dispatch at runtime. The supported units vary by operation. For example, Carbon can add a century, but its `diffInUnit()` has no century unit. `DifferenceOptions::default()` uses signed results and Carbon's default zone handling. The filtered weekday and weekend-day functions return integer counts.

## Localized formats and relative times

Carbon offers two format languages. `iso_format` uses Moment-style tokens and escapes literal text
with brackets. `translated_format` uses PHP `date()` letters and translates month names, weekday
names, meridiems and ordinal suffixes. Both helpers use English by default. Pass a `Locale` to the
corresponding `_in` helper to select a translation for a single call.

```rust
use laravel_rust_format_core::carbon::{
    Locale, Relative, calendar_in, diff_for_humans_in, iso_format, translated_format_in,
};

let day = jiff::civil::date(2024, 2, 29);
let time = day.at(14, 30, 0, 0);
let french = Locale::new("fr");
let russian = Locale::new("ru");

assert_eq!(iso_format(time, "dddd, MMMM Do [at] LT").unwrap(), "Thursday, February 29th at 2:30 PM");
assert_eq!(translated_format_in(russian, day, "j F").unwrap(), "29 февраля");
assert_eq!(calendar_in(french, time, day).unwrap(), "Aujourd’hui à 14:30");

let now = "2024-02-29T14:30:00+00:00[UTC]".parse().unwrap();
let earlier = day.at(12, 30, 0, 0);
assert_eq!(diff_for_humans_in(french, earlier, Relative::Now(now)).unwrap(), "il y a 2 heures");
```

Month and weekday forms can depend on the full format. For example, Polish `MMMM` yields
`luty`, while `D MMMM` yields `29 lutego` on February 29. Carbon's `e`
token numbers weekdays from Sunday. Locale week settings apply to `w` and `g` families.

`calendar` uses the subject's time zone to interpret the comparison date. Use `Relative::To`
for localized before/after wording or `Relative::Now` for localized ago/from-now wording.
References are explicit and the results are independent of the system clock. Select the same locale on `DiffForHumans` to combine precision, joining, tense and short forms.

```rust
use laravel_rust_format_core::carbon::{DiffForHumans, Locale, Relative};
let other = "2024-02-29T14:30:00+00:00[UTC]".parse().unwrap();
let earlier = jiff::civil::date(2024, 2, 29).at(12, 0, 0, 0);
assert_eq!(
    DiffForHumans::new().locale(Locale::new("fr")).parts(2).join()
        .apply(earlier, Relative::To(&other)).unwrap(),
    "2 heures et 30 minutes avant",
);
```

Community package, not affiliated with Laravel.

## Durations and date periods

`Interval` preserves Carbon's component fields, including unbalanced units and
the invert flag. Cascade explicitly to carry between units. Carbon counts four
weeks per month when cascading. To specify a different ratio, pass a
`CascadeFactors` value to `cascade_with` or `total_with`.

```rust
use laravel_rust_format_core::carbon::{CalendarUnit, DiffForHumans, Interval, Locale};

let duration = Interval::minutes(90).cascade()?;
let options = DiffForHumans::for_interval().join().locale(Locale::new("fr"));
assert_eq!(duration.for_humans(&options)?, "1 heure et 30 minutes");
assert_eq!(duration.format("%H:%I"), "01:30");
assert_eq!(duration.total(CalendarUnit::Hour)?, 1.5);
# Ok::<(), laravel_rust_format_core::Error>(())
```

Use `Interval::from_spec` for ISO duration designators, `from_string` for compact
English units such as `2h 5m`, or `from_parts` to supply the raw fields. The
default `spec()` drops the invert flag and microseconds. The two switches to
`spec_with` request those components using Carbon's serialization rules.

`diff(a, b)` and `diff_as_carbon_interval(a, b, absolute)` return the native
calendar fields in the first date's time zone. `format("%a")` prints total days,
and `total` uses the original endpoints where available.

Use `Interval::from(span)` and `Span::try_from(interval)` to move between
Jiff and Carbon units. Weeks collapse into days, and the conversion to Jiff
requires a common sign on all fields. Diff metadata stays with the interval.

```rust
use jiff::civil::date;
use laravel_rust_format_core::carbon::{Period, diff};

assert_eq!(diff(date(2024, 1, 31), date(2024, 3, 1))?.format("%m months %d days (%a total)"),
           "1 months 1 days (30 total)");
let period = Period::from_spec("R3/2024-01-31/P1M")?;
let dates = period.to_array()?;
assert_eq!(dates[1].date(), date(2024, 3, 2));
# Ok::<(), laravel_rust_format_core::Error>(())
```

A period can have a recurrence count, an end, or both. The count describes
yielded dates, including after excluding the start. Calendar-only steps keep
local time across DST. Periods with time fields step in UTC and return dates in
the original zone. A caller can use `iter_capped` with an open period. The
`to_array` method applies the crate's collection budget.

`shift_timezone` keeps the clock fields when changing zones. Use
`start_of_week_in`, `end_of_week_in` and `week_of_year_in` for locale-specific
weeks, or `iso_week_of_year` for the ISO week number.
