PerMalmberg/libcron

Build Problems using MSVC v142 Toolset

HpLightcorner opened this issue · 4 comments

Hey,
First of all, really great work! I may have found an issue when building libcron for a library. Maybe you can take a further look at my problem? I also added a proposal to solve the issue. If you want, I can open a pull request.

Issue:
When trying to build libcron, I am facing an error in the following function:
CronSchedule::calculate_from(const std::chrono::system_clock::time_point& from) const

in file CronSchedule.cpp at line 49. "date::weekday" cannot be converted to unsigned int:

if (data.get_day_of_week().find(static_cast<DayOfWeek>((unsigned)ymw.weekday())) ==
    data.get_day_of_week().end())
{
    sys_days s = ymd;
    curr = s;
    curr += days{1};
    date_changed = true;
}

Suggested Solution:
I would suggest to use the c_encoding function offered by the date library:

if (data.get_day_of_week().find(static_cast<DayOfWeek>(ymw.weekday().c_encoding())) ==
    data.get_day_of_week().end())
{
    sys_days s = ymd;
    curr = s;
    curr += days{1};
    date_changed = true;
}

This should be compatible with the given DayOfWeek enum.

Environment/Task:
Trying to build libcron for x64 Target as Debug and Release Build and as a static library.

Could you please verify my approach or do you have other hints?
Kind regards,
Heinz

Well, c_cenconding does the cast, so lets use it. Please make a PR with the change. Also, it might be a good idea to update the date-library to the latest version while we're at it. Just make sure the tests all pass. :)

I'm curious, can you tell me anything about the project you will use libcron in?

I will prepare the pull request - just give me some time so that I can setup my environment to do all the tests as well :)

I am going to use libcron as a scheduler for a data acquisition system. The logging timepoints (e.g. every 5 seconds, every hour etc.) can be setup for each sensor stream by using a yaml-config file. libcron shall then trigger the logging action to the database. This allows me to decouple the event-driven (on-change) incoming data stream from the plants/sensors to a more deterministic (e.g. every 5 seconds etc.) data stream to the database - which makes data analysis, plotting etc. more easy.

I hope I was able to explain the idea of the use-case :)

The tests should run without additional work if you're able to compile the library itself, the CMake file should create a target for the tests.

Sounds like a perfect use-case for it. Is this part of a project you're doing at university? I'd love to hear how it turns out. It is always nice to see people make use of the projects I put on GitHub.

Yes, a university project for my PhD Studies 😊 My first prototypes with libcron are promising - I will keep you up to date.

I think we can close the issue?