Skip to content

set options timeZoneName is not working #25

@ebsi-lruiz

Description

@ebsi-lruiz

Hello,
I'm trying to use the options to set the timeZoneName so the string comes formatted using that time zone

I have something like this

const config = {  year: 'numeric',  month: 'short',  day: 'numeric',  timeZoneName: 'UTC', }
const formatter = new DateTimeFormat("en", config)
const result = formatter.format(new Date("2020-01-01")) 

the result should be Jan 1, 2020, but the timeZoneName is being ignored, I'm receiving Dec 31, 2019, instead

Looking at the code, I think I found a solution for that, it could be done in the formatNative function
something like this

// -- ios
...
const timeZone: NSTimeZone = getNativeTimeZone(timeZoneName);
        if (timeZone) {
            dateFormatter.timeZone = timeZone;
        }
...

// -- android
...
const timeZone: java.util.TimeZone = getNativeTimeZone(timeZoneName);
        if (timeZone) {
            sdf.setTimeZone(timeZone);
        }
...

Creating the corresponding getNativeTimeZone methods

If you'd like I can make the pull request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions