graphene icon indicating copy to clipboard operation
graphene copied to clipboard

use default timezone by utc ?

Open niceilm opened this issue 9 years ago • 1 comments

in DateTime(Scalar)

AsIs

    @staticmethod
    def serialize(dt):
        assert isinstance(dt, (datetime.datetime, datetime.date)), (
            'Received not compatible datetime "{}"'.format(repr(dt))
        )

        return dt.isoformat()

no timezone dt.isoformat() result

'2017-11-01T20:24:41.928741'

utc timezone dt.isoformat() result

'2017-11-01T20:24:41.928741+00:00'

very difference in javascript

new Date('2017-11-01T20:24:41.928741')
new Date('2017-11-01T20:24:41.928741+00:00')

ToBe

    @staticmethod
    def serialize(dt):
        assert isinstance(dt, (datetime.datetime, datetime.date)), (
            'Received not compatible datetime "{}"'.format(repr(dt))
        )

        if not dt.tzinfo:
            dt = dt.replace(tzinfo=datetime.timezone.utc)

        return dt.isoformat()

use default timezone by utc

What do you think about that?

niceilm avatar Nov 01 '17 11:11 niceilm

I don't think graphene should be responsible for defining the default timezone for a datetime since it could misrepresent the actual timezone for the underlying value. If the datetime value is timezone aware then it will be represented in the response accurately. If the datetime value is not timezone aware then we can't assume it is in UTC.

It is the responsibility of the developer to ensure that timezone aware datetimes are resolved for any DateTime types and not the framework.

jkimbo avatar Feb 18 '18 17:02 jkimbo