Skip to content

PG types without timezone being parsed into time.Times with. #329

@e-dard

Description

@e-dard

Hi,

I briefly discussed this with @johto in #postgresql.

Currently, when a time-based PG type that doesn't have timezone information is parsed into a Go type, it's parsed into a time.Time that does contain timezone information. Specifically, the resulting time.Time contains a single zone in the Location, while the zero-value for a time.Location would contain an empty slice of zones, i.e., the absence of any timezones.

Given the PG value '2015-01-13'::date it should be equivalent to the following time.Time:

time.Time{
        sec: 63556704000, 
        nsec: 0, 
        // zero value for a *time.Location
        loc: &time.Location{
                name: "", 
                zone: []time.zone(nil), 
                tx: []time.zoneTrans(nil), 
                cacheStart: 0, 
                cacheEnd: 0, 
                cacheZone: (*time.zone)(nil),
         },
}

Currently, lib/pq would return the following time.Time:

time.Time{
    sec: 63556704000, 
    nsec: 0, 
    loc: &time.Location{
        name: "", 
        zone: []time.zone{
            time.zone{
                name: "", 
                offset: 0, 
                isDST: false,
            },
        }, 
        tx: []time.zoneTrans{
            time.zoneTrans{
                when: -9223372036854775808, 
                index: 0x0, 
                isstd: false, 
                isutc: false},
            },
        },
        cacheStart: -9223372036854775808, 
        cacheEnd: 9223372036854775807, 
        cacheZone:(*time.zone)(0xc20801eaa0),
    },
}

I'm don't think this is correct because the time.Location produced by lib/pq contains zone information, even if the zone is itself the zero-value.

I would be happy to put a fix in for this, but wanted to see if there was support for that idea or not? I've added a PR with a test case highlighting the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions