-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeslime.h
151 lines (111 loc) · 4.16 KB
/
timeslime.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Time Slime - Command Line Time Sheet
*
* Authors: Michael Rouse
*/
#ifndef __TIME_SLIME_H__
#define __TIME_SLIME_H__
#include "third_party/sqlite3/sqlite3.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Constants */
/* These are used when you want to use the current date */
#define TIMESLIME_DATE_NOW (TIMESLIME_DATE_t){ 0, 0, 0}
#define TIMESLIME_TIME_NOW (TIMESLIME_DATETIME_t){ 0, 0, 0, -1, -1 }
#ifndef TIMESLIME_DATABASE_FILE_NAME
#define TIMESLIME_DATABASE_FILE_NAME "timeslime.db"
#endif
#ifndef TIMESLIME_DEFAULT_RESULT_LIMIT
#define TIMESLIME_DEFAULT_RESULT_LIMIT 1000
#endif
#define TIMESLIME_DATETIME_STR_LENGTH 50
/* Result Codes */
#define TIMESLIME_OK 0
#define TIMESLIME_UNKOWN_ERROR 100
#define TIMESLIME_SQLITE_ERROR 50
#define TIMESLIME_INVALID_YEAR 10
#define TIMESLIME_INVALID_MONTH 11
#define TIMESLIME_INVALID_DAY 12
#define TIMESLIME_INVALID_HOUR 13
#define TIMESLIME_INVALID_MINUTE 14
#define TIMESLIME_NOT_INITIALIZED 99
#define TIMESLIME_ALREADY_CLOCKED_IN 60 /* When you try to clock in without clocking out */
#define TIMESLIME_NOT_CLOCKED_IN 61 /* When you try to clock out without clocking in */
#define TIMESLIME_NO_ENTIRES 80
/* Datatypes */
typedef int TIMESLIME_STATUS_t;
struct TIMESLIME_DATE_STRUCT
{
int year;
int month;
int day;
};
typedef struct TIMESLIME_DATE_STRUCT TIMESLIME_DATE_t;
struct TIMESLIME_DATETIME_STRUCT
{
int year;
int month;
int day;
int hour;
int minute;
};
typedef struct TIMESLIME_DATETIME_STRUCT TIMESLIME_DATETIME_t;
// Report Entry
struct TIMESLIME_REPORT_ENTRY_STRUCT
{
float Hours;
char Date[TIMESLIME_DATETIME_STR_LENGTH];
};
typedef struct TIMESLIME_REPORT_ENTRY_STRUCT TIMESLIME_REPORT_ENTRY_t;
// Time Sheet Report
struct TIMESLIME_REPORT_STRUCT
{
int NumberOfEntries;
float TotalHours;
TIMESLIME_REPORT_ENTRY_t Entries[];
};
typedef struct TIMESLIME_REPORT_STRUCT TIMESLIME_REPORT_t;
/* Initialize the Time Slime library */
TIMESLIME_STATUS_t TimeSlime_Initialize(char directory_for_database[]);
/* Safely close out of the Time Slime library */
TIMESLIME_STATUS_t TimeSlime_Close(void);
/* Add to the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_AddHours(float hours, TIMESLIME_DATE_t date);
/* Clock in to the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_ClockIn(TIMESLIME_DATETIME_t time);
/* Clock out of the Time Slime time sheet */
TIMESLIME_STATUS_t TimeSlime_ClockOut(TIMESLIME_DATETIME_t time);
/* Gets the time sheet for a period of time */
TIMESLIME_STATUS_t TimeSlime_GetReport(TIMESLIME_DATE_t start, TIMESLIME_DATE_t end, TIMESLIME_REPORT_t **out);
/* Frees memory allocated for report used in report method */
void TimeSlime_FreeReport(TIMESLIME_REPORT_t **report);
/* Converts status to friendly error code (or returns SQLITE error string) */
char* TimeSlime_StatusCode(TIMESLIME_STATUS_t status);
/* Queries (Do not touch) */
#define __TS_QRY_GET_COMPLTED_CLOCK_ENTRIES "(ClockInTime IS NOT NULL AND ClockOutTime IS NOT NULL)"
#define __TS_QRY_GET_PARTIAL_CLOCK_ENTRIES "(ClockOutTime IS NULL AND ClockInTime IS NOT NULL)"
#define __TS_QRY_GET_ADDED_HOURS "(HoursAdded <> 0.0 AND HoursAddedDate IS NOT NULL)"
#define __TS_QRY_GET_ALL_ENTIRES __TS_QRY_GET_COMPLTED_CLOCK_ENTRIES " OR " __TS_QRY_GET_ADDED_HOURS
/* Versioning, do not touch unless increasing the version */
#define _TO_VERSION_STRING(v) "v"__TO_VERSION_STRING(v)
#define __TO_VERSION_STRING(v) #v
#ifdef TIMESLIME_VERSION
#undef TIMESLIME_VERSION
#endif
#define TIMESLIME_VERSION 0.9
#ifdef TIMESLIME_VERSION_STR
#undef TIMESLIME_VERSION_STR
#endif
#define TIMESLIME_VERSION_STR _TO_VERSION_STRING(TIMESLIME_VERSION)
#ifndef TIMESLIME_FILE_PATH_SEPARATOR
#ifdef _WIN32
#define TIMESLIME_FILE_PATH_SEPARATOR "\\"
#else
#define TIMESLIME_FILE_PATH_SEPARATOR "/"
#endif
#endif
/* Date helper functions */
#define _TIMESLIME_IS_DATE_TODAY(date) (date.year == 0 && date.month == 0 && date.day == 0)
#define _TIMESLIME_IS_TIME_NOW(time) (time.year == 0 && time.month == 0 && time.day == 0 && time.hour == -1 && time.minute == -1)
#endif