Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

lastModified() on LocalizedTerm returning incorrect date #408

Closed
tanerkay opened this issue Mar 12, 2025 · 1 comment · Fixed by #409
Closed

lastModified() on LocalizedTerm returning incorrect date #408

tanerkay opened this issue Mar 12, 2025 · 1 comment · Fixed by #409
Labels
bug Something isn't working

Comments

@tanerkay
Copy link

Bug description

Similar to #65, except this time for Statamic\Taxonomies\LocalizedTerm.

Bit more difficult to solve this time, as there is no Statamic\Contracts\Taxonomies\LocalizedTerm to create a new binding for.

The lastModified() method in LocalizedTerm is checking for updated_at as a timestamp, but in Eloquent, the updated_at is a Carbon instance. So what is happening is the string version of the Carbon instance is being parsed into a timestamp, which results in approximately 2100 seconds (Carbon adds the integer values of each part of the date string for some reason, e.g. 2025-03-12 10:50:35 results in 2025 + 3 + 12 + 10 + 50 + 35 = 2135 or 2135 seconds past the Unix epoch).

How to reproduce

use Statamic\Eloquent\Taxonomies\Taxonomy;
use Statamic\Facades\Term as TermFacade;
use Statamic\Taxonomies\LocalizedTerm;
    
Taxonomy::make('test')->title('test')->save();

tap(TermFacade::make('test-term')->taxonomy('test')->data([]))->save();

/** @var LocalizedTerm $term */
$term = TermFacade::query()->first();
$term->set('foo', 'bar');
$term->save();

$term->updated_at->toDateTimeString();
// example output: 1970-01-01 00:35:26
// note that actual time will depend on when the command is run

or as a test:

use Statamic\Eloquent\Taxonomies\Taxonomy;
use Statamic\Facades\Term as TermFacade;
use Statamic\Taxonomies\LocalizedTerm;

#[Test]
public function it_saves_updated_at_value_correctly()
{
    $this->freezeSecond();

    Taxonomy::make('test')->title('test')->save();

    tap(TermFacade::make('test-term')->taxonomy('test')->data([]))->save();

    /** @var LocalizedTerm $term */
    $term = TermFacade::query()->first();
    $term->set('foo', 'bar');
    $term->save();

    $this->assertEquals(now(), $term->updated_at);
}

Logs

Environment

Can be reproduced on a fresh clone of https://github.com/statamic/eloquent-driver

Additional details

No response

@tanerkay tanerkay added the bug Something isn't working label Mar 12, 2025
@ryanmitchell
Copy link
Contributor

ryanmitchell commented Mar 12, 2025

Should be easily solved - #409

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants