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

Read date time cell from Google table #1852

Closed
skynin opened this issue Feb 13, 2021 · 4 comments
Closed

Read date time cell from Google table #1852

skynin opened this issue Feb 13, 2021 · 4 comments

Comments

@skynin
Copy link

skynin commented Feb 13, 2021

This is:

- [*] a bug report

What is the expected behavior?

I have a google table with column:

2021-02-15 20:30:00
2021-02-14 23:00:00
2021-02-15 03:45:00

$eachCell->getStyle()->getNumberFormat()->getFormatCode() returns:
'yyyy"-"mm"-"dd" "hh":"mm":"ss',

and $eachCell->getFormattedValue() returns:
2021-02-15 20:02:00
2021-02-14 23:02:00
2021-02-15 03:02:00

My the dirty fix

namespace PhpOffice\PhpSpreadsheet\Style;

class NumberFormat extends Supervisor

    public function getFormatCode() {
        return str_replace(':"mm"', ':"i"', $this->getOriginalFormatCode());
    }
    public function getOriginalFormatCode() // rename original method
    {
        if ($this->isSupervisor) {
            return $this->getSharedComponent()->getFormatCode();
        }
        if ($this->builtInFormatCode !== false) {
            return self::builtInFormatCode($this->builtInFormatCode);
        }

        return $this->formatCode;
    }

My another fix didnt help:

class NumberFormat extends Supervisor

private static $dateFormatReplacements = [

        'mmm' => 'M',
        //    mm is minutes if time, but can also be month w/leading zero
        //    so we try to identify times be the inclusion of a : separator in the mask
        //    It isn't perfect, but the best way I know how
        ':mm' => ':i',
        'mm:' => 'i:',
        ':"mm"' => ':"i"', // skynin
        '"mm":' => '"i":', // skynin

Which versions of PhpSpreadsheet and PHP are affected?

"version": "1.16.1"

@MarkBaker
Copy link
Member

Please try against the latest master branch

@skynin
Copy link
Author

skynin commented Apr 13, 2021

"version": "1.17.1",

This issue is actual.
My fix:
return str_replace(':"mm"', ':"i"', $this->getOriginalFormatCode());

$dateFormatReplacements wasn't changed

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Jun 26, 2021
@oleibman
Copy link
Collaborator

Fixed by PR #1891

@oleibman oleibman removed the stale label Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants