New issue

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

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

Already on GitHub? Sign in to your account

Time (as part of date) ignored when Entry is created programatically #1644

Closed
peda opened this Issue Nov 6, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@peda

peda commented Nov 6, 2017

Expected behaviour

Time should be set same as this is done when editing a entry through the CP

Actual behaviour

The time part gets thrown away and only the date part is used

Steps to reproduce

$entry = Entry::create('my-post')
    ->collection('blog')
    ->with(['title' => 'My First Post'])
    ->published(false)
    ->date('2016-05-10 13:59:15')
    ->get();

$entry->save();

Server Details

Operating System: Ubuntu 14.04

Web Server: Apache 2

PHP Version: PHP 7

Statamic Version: 2.7.1

Updated from an older Statamic or fresh install: updated

List of installed addons: N/A

How to fix

Statamic\Data\Entries\EntryFactory

    /**
     * @param string $date
     * @return $this
     */
    public function date($date = null)
    {
        $date = ($date) ? Carbon::parse($date) : Carbon::now();

        $this->order = $date->toDateString(); 

        return $this;
    }

toDateString() does return Y-m-d but it should only be Y-m-d if there is no time part - if there is a time part the date format should be Y-m-d-Hi (as used in Entry->date())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment