Skip to content

PgsqlAdapter and CarbonDateFormat date format mismatch #62

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

Open
alexsmirnovdotcom opened this issue May 14, 2024 · 1 comment
Open

PgsqlAdapter and CarbonDateFormat date format mismatch #62

alexsmirnovdotcom opened this issue May 14, 2024 · 1 comment

Comments

@alexsmirnovdotcom
Copy link

PgsqlAdapter for query in 'hour' interval get 'YYYY-MM-DD HH24:00:00' format.
But CarbonDateFormat for 'hour' interval get 'Y-m-d H:00'.
This is get a duplicated empty TrendValue`s because from database receives with seconds, and generate stubs without.

@neutronstein
Copy link

This issue can be easily resolved by extending Trend class, overriding getCarbonDateFormat function and using the new class instead.

class TrendX extends \Flowframe\Trend\Trend
{
    protected function getCarbonDateFormat(): string
    {
        if($this->interval == 'hour') {
           return 'Y-m-d H:00:00';
        }
        return parent::getCarbonDateFormat();
    }
}

// Usage
TrendX::model(User::class)->between(...)->perHour()->count()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants