#define THIRTY_MINUTES 1800
#define FOURTY_FIVE_MINITUES 2700
-time_t get_break_time(time_t worktime)
+time_t get_break_time(const time_t worktime)
{
if (worktime > SIX_HOURS_FOURTY_FIVE_MINUTES)
return FOURTY_FIVE_MINITUES;
#define BREAK_H
#include <time.h>
-time_t get_break_time(time_t worktime);
+time_t get_break_time(const time_t worktime);
#endif
\ No newline at end of file
return value;
}
-int main(int argc, const char* argv[])
+int main(const int argc, const char* argv[])
{
if (argc < 3) {
printf("ERROR: %s <begin_hours> <begin_minutes>\n", argv[0]);
#include "validate.h"
#include "xml.h"
-int main(int argc, char* argv[])
+int main(const int argc, const char* argv[])
{
if (argc < 2) {
printf("ERROR: %s <init|add|dateadd|merge|version>\n", argv[0]);
return new_str;
}
-char* get_time_str(time_t timediff)
+char* get_time_str(const time_t timediff)
{
int8_t hour = timediff / ONE_HOUR;
int16_t rest_minutes = timediff % ONE_HOUR;
return timestr;
}
-char* get_time_overtime_str(time_t timediff)
+char* get_time_overtime_str(const time_t timediff)
{
return get_time_str(timediff * -1);
}
-char* get_weekday_str(uint8_t wday)
+char* get_weekday_str(const uint8_t wday)
{
switch (wday) {
case 0:
}
}
-char* get_weekday_short_str(uint8_t wday)
+char* get_weekday_short_str(const uint8_t wday)
{
switch(wday) {
case 0:
}
}
-char* get_date_str(struct tm date)
+char* get_date_str(const struct tm date)
{
char* datestr = malloc(sizeof(char) * MAX_TIME_STR_LENGTH);
if (datestr == NULL)
return datestr;
}
-char* get_time_str_from_tm(struct tm time)
+char* get_time_str_from_tm(const struct tm time)
{
char* timestr = malloc(sizeof(char) * MAX_TIME_STR_LENGTH);
if (timestr == NULL)
#include <stdint.h>
#include <time.h>
-char* get_time_str(time_t timediff);
-char* get_time_overtime_str(time_t timediff);
-char* get_weekday_str(uint8_t wday);
-char* get_weekday_short_str(uint8_t wday);
-char* get_date_str(struct tm date);
-char* get_time_str_from_tm(struct tm time);
+char* get_time_str(const time_t timediff);
+char* get_time_overtime_str(const time_t timediff);
+char* get_weekday_str(const uint8_t wday);
+char* get_weekday_short_str(const uint8_t wday);
+char* get_date_str(const struct tm date);
+char* get_time_str_from_tm(const struct tm time);
time_t get_seconds_from_str(const char* timestr);
uint16_t get_year_from_str(const char* date);
#define TEN_HOURS 36000
#define ONE_DAY 86400
-time_t get_brutto_worktime(time_t begin, time_t now)
+time_t get_brutto_worktime(const time_t begin, const time_t now)
{
- if (begin > now)
- now += ONE_DAY;
+ time_t tmp_now = now;
- return difftime(now, begin);
+ if (begin > tmp_now)
+ tmp_now += ONE_DAY;
+
+ return difftime(tmp_now, begin);
}
-time_t get_current_worktime(time_t begin, time_t now)
+time_t get_current_worktime(const time_t begin, const time_t now)
{
- if (begin > now)
- now += ONE_DAY;
+ time_t tmp_now = now;
+
+ if (begin > tmp_now)
+ tmp_now += ONE_DAY;
- time_t worktime = difftime(now, begin);
+ time_t worktime = difftime(tmp_now, begin);
worktime -= get_break_time(worktime);
return worktime;
}
-time_t get_eight_hour_end_worktime(time_t begin)
+time_t get_eight_hour_end_worktime(const time_t begin)
{
time_t worktime = begin + SOLL_WORKTIME;
worktime += get_break_time(worktime);
return worktime;
}
-time_t get_ten_hour_end_worktime(time_t begin)
+time_t get_ten_hour_end_worktime(const time_t begin)
{
time_t worktime = begin + TEN_HOURS;
worktime += get_break_time(worktime);
return worktime;
}
-time_t get_current_worktime_diff_to_end_eight_hour(time_t begin, time_t now)
+time_t get_current_worktime_diff_to_end_eight_hour(const time_t begin, const time_t now)
{
return SOLL_WORKTIME - get_current_worktime(begin, now);
}
-time_t get_current_worktime_diff_to_end_ten_hour(time_t begin, time_t now)
+time_t get_current_worktime_diff_to_end_ten_hour(const time_t begin, const time_t now)
{
return TEN_HOURS - get_current_worktime(begin, now);
}
\ No newline at end of file
#define ONE_MINUTE 60
#define SOLL_WORKTIME SOLL_HOUR * ONE_HOUR + SOLL_MINUTES * ONE_MINUTE
-time_t get_brutto_worktime(time_t begin, time_t now);
-time_t get_current_worktime(time_t begin, time_t now);
-time_t get_eight_hour_end_worktime(time_t begin);
-time_t get_ten_hour_end_worktime(time_t begin);
-time_t get_current_worktime_diff_to_end_eight_hour(time_t begin, time_t now);
-time_t get_current_worktime_diff_to_end_ten_hour(time_t begin, time_t now);
+time_t get_brutto_worktime(const time_t begin, const time_t now);
+time_t get_current_worktime(const time_t begin, const time_t now);
+time_t get_eight_hour_end_worktime(const time_t begin);
+time_t get_ten_hour_end_worktime(const time_t begin);
+time_t get_current_worktime_diff_to_end_eight_hour(const time_t begin, const time_t now);
+time_t get_current_worktime_diff_to_end_ten_hour(const time_t begin, const time_t now);
#endif
\ No newline at end of file
#define MAX_STRING_LENGTH 36
#define CHUCK_SIZE 32
-memFile* _init_mem() {
- memFile* mem = malloc(sizeof(memFile));
+mem_file_t* _init_mem() {
+ mem_file_t* mem = malloc(sizeof(mem_file_t));
if (mem == NULL)
return NULL;
return mem;
}
-void free_mem(memFile* mem) {
+void free_mem(mem_file_t* mem) {
free(mem->data);
mem->data = NULL;
}
-void _alloc_chunk(memFile* mem)
+void _alloc_chunk(mem_file_t* mem)
{
mem->size += CHUCK_SIZE;
char* tmpmem = realloc(mem->data, sizeof(char) * mem->size);
mem->data = tmpmem;
}
-void _shrink_mem(size_t readed, memFile* mem)
+void _shrink_mem(const size_t readed, mem_file_t* mem)
{
mem->size = readed;
char* tmpmem = realloc(mem->data, sizeof(char) * mem->size);
mem->data = tmpmem;
}
-void _read_stdin_into_memory(memFile* mem)
+void _read_stdin_into_memory(mem_file_t* mem)
{
char* buf = malloc(sizeof(char));
buf = NULL;
}
-char* _read_last_saldo(memFile* mem)
+char* _read_last_saldo(mem_file_t* mem)
{
char* saldostr = malloc(sizeof(char) * MAX_STRING_LENGTH);
if (saldostr == NULL)
xmlElemContent = NULL;
}
-struct tm _init_tm_with_date(const char* date, uint8_t hour, uint8_t min)
+struct tm _init_tm_with_date(const char* date, const uint8_t hour, const uint8_t min)
{
struct tm value;
const time_t now = time(NULL);
void _write_entry_node(xmlTextWriterPtr xmlWriter,
const char* date,
- uint8_t begin_hour,
- uint8_t begin_min,
- uint8_t end_hour,
- uint8_t end_min,
- time_t last_saldo)
+ const uint8_t begin_hour,
+ const uint8_t begin_min,
+ const uint8_t end_hour,
+ const uint8_t end_min,
+ const time_t last_saldo)
{
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);
}
void add_entry(const char* date,
- uint8_t begin_hour,
- uint8_t begin_min,
- uint8_t end_hour,
- uint8_t end_min)
+ const uint8_t begin_hour,
+ const uint8_t begin_min,
+ const uint8_t end_hour,
+ const uint8_t end_min)
{
- memFile* file_content = _init_mem();
+ mem_file_t* file_content = _init_mem();
_read_stdin_into_memory(file_content);
char* saldostr = _read_last_saldo(file_content);
typedef struct {
char* data;
size_t size;
-} memFile;
+} mem_file_t;
void init_time_acount();
void add_entry(const char* date,
- uint8_t begin_hour,
- uint8_t begin_min,
- uint8_t end_hour,
- uint8_t end_min);
+ const uint8_t begin_hour,
+ const uint8_t begin_min,
+ const uint8_t end_hour,
+ const uint8_t end_min);
void merge(const char* dir);
#endif
\ No newline at end of file