spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.98k stars 184 forks source link

`spacetime.whereIts` returns an array of timezones names lowercased #212

Open imns opened 4 years ago

imns commented 4 years ago

Title pretty much says it all. If I call spacetime.whereIts('4pm') it returns:

[                                                                                                                                                                                                                                                                                                                                                                 
  'america/lima',
  'america/rio_branco',
  'brazil/acre',
  'america/bahia_banderas',
  'america/merida',
  'america/mexico_city',
  'america/monterrey',
  'mexico/general',
  'america/north_dakota',
  'america/chicago',
  'america/knox_in',
  'america/matamoros',
  'america/menominee',
  'america/rainy_river',
  'america/rankin_inlet',
  'america/resolute',
  ...
]

I would expect the timezone names to be in the same format as in the documentation ie: "America/Jamaica" as referenced here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.

imns commented 4 years ago

As a quick/dirty fix I did this, but I'm certain it doesn't cover all the edge cases:

function titleCase(str) {
    return str
        .toLowerCase()
        .split("_")
        .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
        .join("_")
        .replace("Gmt", "GMT");
}
const tzs = spacetime.whereIts("4pm").map((tz) => {
    let [country, region] = tz.split("/");
    return `${titleCase(country)}/${titleCase(region)}`;
});
spencermountain commented 4 years ago

ah, yeah you're right. I'll add this to the next major.

yeah - there is America/Port-au-Prince and Antarctica/DumontDUrville, and also the GMT ones and things. thanks for the heads-up

Great-hijack commented 2 years ago

Thanks for this great library. 🎉

When can we expect the next release with this resolved?

spencermountain commented 2 years ago

hey @Great-hijack - sorry for the delay on this. Fraid v8 is looking like mid-summer. cheers