Skip to content
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

Dashboard Graph is skipping Months in 1y view #3593

Open
Hanmac opened this issue Oct 11, 2023 · 6 comments · May be fixed by #3594
Open

Dashboard Graph is skipping Months in 1y view #3593

Hanmac opened this issue Oct 11, 2023 · 6 comments · May be fixed by #3594

Comments

@Hanmac
Copy link
Contributor

Hanmac commented Oct 11, 2023

Preconditions (*)

  1. Have OpenMage with Dashboard Graph enabled

Steps to reproduce (*)

  1. Open the Backend with Dashboard, and select 1y for period

Expected result (*)

  1. have a graph with all the months (or at least the data from all months)

Actual result (*)

testgraph

The Faulty Code piece:

        while($dateStart->compare($dateEnd) < 0){
            switch ($this->getDataHelper()->getParam('period')) {
                case '24h':
                    $d = $dateStart->toString('yyyy-MM-dd HH:00');
                    $dateStart->addHour(1);
                    break;
                case '7d':
                case '1m':
                    $d = $dateStart->toString('yyyy-MM-dd');
                    $dateStart->addDay(1);
                    break;
                case '1y':
                case '2y':
                    $d = $dateStart->toString('yyyy-MM');
                    $dateStart->addMonth(1);
                    break;
            }

Results in this data from $dateStart (is there a logic behind this jumps for addMonth?)

01.01.2023 00:00:00
03.03.2023 00:00:00
01.04.2023 00:00:00
30.05.2023 00:00:00
01.06.2023 00:00:00
30.07.2023 00:00:00
01.08.2023 00:00:00
01.10.2023 00:00:00

and uses this for fields:

Array
(
    [0] => 2023-01
    [1] => 2023-03
    [2] => 2023-04
    [3] => 2023-05
    [4] => 2023-06
    [5] => 2023-07
    [6] => 2023-08
    [7] => 2023-10
)

this results in the graph missing a few months

Probably solution would be to use DateTime instead of Zend_Date ?

@fballiano
Copy link
Contributor

I've tested this on a customer's website and I can confirm:
"chxl": "0:|01/2023|03/2023|04/2023|05/2023|06/2023|07/2023|08/2023|10/2023

february and september are missing...

@fballiano
Copy link
Contributor

I've also done this:

        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";
        $dateStart->addMonth(1);
        echo $dateStart . "\n";

and it outputs:

Jan 1, 2023 12:00:00 AM
Feb 1, 2023 12:00:00 AM
Mar 1, 2023 12:00:00 AM
May 1, 2023 12:00:00 AM
Jul 1, 2023 12:00:00 AM
Aug 31, 2023 12:00:00 AM
Sep 1, 2023 12:00:00 AM
Oct 30, 2023 12:00:00 AM
Nov 30, 2023 12:00:00 AM
Dec 30, 2023 12:00:00 AM
Jan 30, 2024 12:00:00 AM
Feb 29, 2024 12:00:00 AM

it's very broken!

@Hanmac
Copy link
Contributor Author

Hanmac commented Oct 11, 2023

I'm especially confused about the small steps its doing between:

30.05.2023 00:00:00
01.06.2023 00:00:00

is that whats called a "month"? ;P i don't know what Zend_Date is doing there

@fballiano
Copy link
Contributor

so, it's a bug with timezone because it you comment out these two lines:

$dateStart->setTimezone($timezoneLocal);
$dateEnd->setTimezone($timezoneLocal);

then it works as expected

@fballiano
Copy link
Contributor

what if we convert those two lines to:

switch ($this->getDataHelper()->getParam('period')) {
            case '1y':
            case '2y':
                break;
            default:
                $dateStart->setTimezone($timezoneLocal);
                $dateEnd->setTimezone($timezoneLocal);
        }

it seems to work for me

@fballiano
Copy link
Contributor

@Hanmac I've rewrote the whole routing using DateTime in #3594 and it seems to work for me.

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

Successfully merging a pull request may close this issue.

3 participants