Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone Database Not Found #641

Open
advra opened this issue Jan 22, 2021 · 6 comments
Open

Timezone Database Not Found #641

advra opened this issue Jan 22, 2021 · 6 comments

Comments

@advra
Copy link

advra commented Jan 22, 2021

I get the following error ""Timezone database not found at "/home/pi/Downloads/tzdata".

I am a bit curious as to how this operates. My software that uses Date runs on a system that does not have internet access. In the past we were able to use the date library without this timezone issue. Looking further into this it appears that upon compilation it would download an XML file to lookup timezones during runtime.

Couple questions:

  1. say the system never connects to the internet how do we retrieve this?
  2. once the file is located in downloads is it safe to assume it does not need to be downloaded again?
  3. is it possible to use the local time settings of the OS (raspberry pi in our case?) as it synchronizes with an NTP server
@HowardHinnant
Copy link
Owner

HowardHinnant commented Jan 22, 2021

  1. The library can be configured to not go to the internet for tzdata. tzdata can either be downloaded manually, and this lib can find it, or (on non-Windows systems), the OS-supplied tzdata can be used.
  2. It depends on the configuration of the library (https://howardhinnant.github.io/date/tz.html#Installation). But yes, it can be configured to not download the tzdata.
  3. I don't know for sure. I presume you're talking about current_zone() which retrieves the computer's currently set local time zone. It may already work for raspberry pi and it may not. If it doesn't, and you can figure out how to make it work for raspberry pi, I would gladly accept a PR. current_zone() is the most non-portable function in the library, and consist of a messy ad-hoc bag of tricks for each platform.

Search for "raspberry pi tzdata" and look for things like: https://www.raspberrypi.org/forums/viewtopic.php?t=145194 If the binary tzdata files are successfully installed on your platform, it is likely that compiling this library with -DUSE_OS_TZDB will just work, and with no internet access. Or you can manually download the text form of the database and compile with -DHAS_REMOTE_API=0, which turns off all internet API.

@advra
Copy link
Author

advra commented Jan 22, 2021

@HowardHinnant Thank you for the detailed information. I will revisit my implementation and let you know if I have any further pending questions. If I continue with the current_zone() route and have an implementation I will make that PR.

Thanks again!

@advra
Copy link
Author

advra commented Jan 25, 2021

So in the interest of time I decide for now to put it in our source directory. I have a lack of knowledge with Make.

For ex /project/src/tzdata. Here is our makefile configuration. Note: The line where LDFLAGS we provided disabling auto download and attempted to redirect the folder.

# Note: -lcurl is required to compile date.h. libvncxx.a is required to link the vectornav library
CC = g++
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
# onboard aircraft binary
EXE1 := instrocoord.a
# ground station binary
EXE2 := instrogcs.a
SRC := $(wildcard $(SRC_DIR)/*.cpp)
OBJ := $(SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
CPPFLAGS := -Iinclude/
CFLAGS   := -Wall -g -std=c++14
LDFLAGS  := -Llib -DAUTO_DOWNLOAD=0 -DINSTALL=~/instro/src/tzdata
LDLIBS   := -lm -lpthread -lstdc++fs lib/vn/build/bin/libvncxx.a -lcurl -pthread -lwiringPi
.PHONY: all clean
all: $(EXE1)
$(EXE1): $(OBJ) | $(BIN_DIR)
    @echo Linking Libraries
    $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
    @echo Compiling individual objects
    $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(BIN_DIR) $(OBJ_DIR):
    # @echo Creating directories for objects Object $(OBJ) and binaries $(BIN_DIR)
    mkdir -p $@
clean:
    @echo Cleaning...
    @$(RM) -rv $(BIN_DIR) $(OBJ_DIR)
    @$(RM) $(EXE1)
-include $(OBJ:.o=.d)

@HowardHinnant
Copy link
Owner

You can eliminate the need for -lcurl with -DHAS_REMOTE_API=0. This removes the ability to download the tzdb programmatically from within the library. Once done, if you want, you can eliminate -DAUTO_DOWNLOAD=0, but you don't have to. AUTO_DOWNLOAD defaults to whatever HAS_REMOTE_API is set to.

@advra
Copy link
Author

advra commented Jan 25, 2021

Thanks. So I downloaded the tzdata folder andI moved it from downloads into my project src. Then in makefile we set it as
-DINSTALL=home/pi/instro/src however the compile error states the following. Any ideas?

terminate called after throwing an instance of 'std::runtime_error'
  what():  Timezone database not found at "home/pi/instro/src/tzdata"
Aborted

@advra
Copy link
Author

advra commented Jan 25, 2021

Update. Nevermind forgot to prepend a / so that it is -DINSTALL=home/pi/instro/src

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants