timestr = NULL;
}
-struct tm get_tm_from_time(const time_t time)
+struct tm _get_tm_from_time(const time_t time)
{
struct tm tm_value;
const struct tm* time_tm = localtime(&time);
return tm_value;
}
+struct tm _init_tm_with_time(const char* hour, const char* min)
+{
+ struct tm value;
+ const time_t now = time(NULL);
+ const struct tm* now_tm = localtime(&now);
+ memcpy(&value, now_tm, sizeof(struct tm));
+
+ if (hour != NULL)
+ value.tm_hour = atoi(hour);
+
+ if (min != NULL)
+ value.tm_min = atoi(min);
+
+ return value;
+}
+
int main(int argc, const char* argv[])
{
- if (argc < 3 || (argc > 3 && argc < 5)) {
- printf("ERROR: %s <begin_hours> <begin_minutes> [<end_hours> <end_minutes>]\n", argv[0]);
+ if (argc < 3) {
+ printf("ERROR: %s <begin_hours> <begin_minutes>\n", argv[0]);
return 1;
}
- if (!validate_hourstring(argv[1])
- || !validate_minutestring(argv[2])) {
+ if (!validate_hourstring(argv[1]) || !validate_minutestring(argv[2])) {
printf("ERROR: one or more invalid arguments\n");
return 1;
}
- if (argc == 5) {
- if (!validate_hourstring(argv[3])
- || !validate_minutestring(argv[4])) {
- printf("ERROR: one or more invalid arguments\n");
- return 1;
- }
- }
-
printf("Version: %s\n\n", PROJECT_VERSION);
- const time_t now = time(NULL);
- const struct tm* tmp_now_tm = localtime(&now);
-
- struct tm begin_tm;
- struct tm end_tm;
- memcpy(&begin_tm, tmp_now_tm, sizeof(struct tm));
- memcpy(&end_tm, tmp_now_tm, sizeof(struct tm));
-
- begin_tm.tm_hour = atoi(argv[1]);
- begin_tm.tm_min = atoi(argv[2]);
- if (argc == 5) {
- end_tm.tm_hour = atoi(argv[3]);
- end_tm.tm_min = atoi(argv[4]);
- }
-
- const time_t begin = mktime(&begin_tm);
- const time_t end = mktime(&end_tm);
+ const struct tm begin_tm = _init_tm_with_time(argv[1], argv[2]);
+ const struct tm end_tm = _init_tm_with_time(NULL, NULL);
+ const time_t begin = mktime((struct tm*) &begin_tm);
+ const time_t end = mktime((struct tm*) &end_tm);
const time_t worktime_eight_end = get_eight_hour_end_worktime(begin);
const time_t worktime_max_end = get_ten_hour_end_worktime(begin);
- const struct tm work_eight_end_tm = get_tm_from_time(worktime_eight_end);
- const struct tm max_work_end_tm = get_tm_from_time(worktime_max_end);
+ const struct tm work_eight_end_tm = _get_tm_from_time(worktime_eight_end);
+ const struct tm max_work_end_tm = _get_tm_from_time(worktime_max_end);
_print_time_now(end_tm);
printf("\n");
{
const struct tm begin_tm = _init_tm_with_date(date, begin_hour, begin_min);
const struct tm end_tm = _init_tm_with_date(date, end_hour, end_min);
- const time_t begin = mktime(&begin_tm);
- const time_t end = mktime(&end_tm);
+ const time_t begin = mktime((struct tm*) &begin_tm);
+ const time_t end = mktime((struct tm*) &end_tm);
const time_t brutto_worktime = get_brutto_worktime(begin, end);
const time_t netto_worktime = get_current_worktime(begin, end);
const time_t overtime = get_current_worktime_diff_to_end_eight_hour(begin, end);