HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.08k stars 670 forks source link

`set_install()` isn't friendly to wide strings on Windows #690

Closed DavisVaughan closed 1 year ago

DavisVaughan commented 2 years ago

Hi Howard,

I have a Windows user who is having issues with set_install() (full info here). The issue is that they unfortunately have an accent mark in their root file path, which I can't have control over. They end up with an error like this:

#> Error: Timezone database not found at "C:/Users/mlyons/OneDrive - COMPANY Namé/Documents-ML/R/win-library/4.1/tzdb/tzdata"

I think the issue is that set_install() only supports std::string, but really std::wstring is needed here? For example, I can sort of reproduce this with the following on a Windows computer (compiling with these defines):

#include <date/tz.h>

void tzdb_test_cpp() {
  std::string path = "C:\\Users\\smwhi\\Documents\\RStudio Projects\\problèm\\tzdata";
  date::set_install(path);
  const date::tzdb& db = date::get_tzdb();
}

The date::get_tzdb() call will throw the "Timezone database not found" error (notice the accent in the "problem" folder)

I think I really need to do something like:

std::wstring path = L"C:\\Users\\smwhi\\Documents\\RStudio Projects\\problèm\\tzdata"

but I can't pass that to set_install().

If you do try and support this, I've also been told that file_exists() should use _waccess() rather than _access() for those wide strings. https://github.com/HowardHinnant/date/blob/d57d764707050fa85fc3a6f824c666ed4550b1b4/src/tz.cpp#L2839

DavisVaughan commented 2 years ago

@HowardHinnant I just wanted to followup and see if you had any thoughts about this issue. Normally I'd never followup like this, but I borked the issue when I opened it originally and that may have caused you to not see it.

HowardHinnant commented 2 years ago

Sorry, just been really busy elsewhere.

DavisVaughan commented 2 years ago

No problem at all!

DavisVaughan commented 1 year ago

Fixed by https://github.com/HowardHinnant/date/commit/529a09267f6f4b1f3ac0ab11864ef452be92dd10