Skip to content

Commit c1a92d5

Browse files
feature: create time module
Co-authored-by: Valentin <[email protected]>
1 parent 0651588 commit c1a92d5

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

libs/main.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
// List
1111
#include "./list/main.h"
1212

13+
// Time
14+
#include "./time/main.h"
15+
1316
#endif // LIBS_MAIN_H_INCLUDED

libs/time/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
#include "./main.h"
3+
4+
#include <stdlib.h>
5+
#include <string.h>
6+
#include <time.h>
7+
8+
unsigned char concatCurrentTime(char* string) {
9+
char timeStore[sizeof("YYYY-MM-DD-HH-mm") + 1];
10+
11+
time_t _time;
12+
struct tm* _pTime;
13+
size_t timeLength;
14+
15+
_time = time(NULL);
16+
_pTime = localtime(&_time);
17+
18+
timeLength = strftime(timeStore, sizeof(timeStore), "%Y-%m-%d-%H-%M", _pTime);
19+
20+
if (timeLength != 16) return 1;
21+
22+
strcat(string, timeStore);
23+
return 0;
24+
}

libs/time/main.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef LIBS__TIME_H_INCLUDED
2+
#define LIBS__TIME_H_INCLUDED
3+
4+
unsigned char concatCurrentTime(char* string);
5+
6+
#endif // LIBS__TIME_H_INCLUDED

0 commit comments

Comments
 (0)