-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_time.c
70 lines (63 loc) · 2.65 KB
/
handle_time.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_time.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jraymond <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/19 15:49:29 by jraymond #+# #+# */
/* Updated: 2018/05/16 15:06:13 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
#include <time.h>
void ft_atime(struct stat *allstats, t_finfo *file_st)
{
char *file_time;
time_t curr_time;
file_time = ctime((const time_t *)&allstats->st_atime);
file_st->time_n = allstats->st_atime;
time(&curr_time);
ft_strncat(file_st->timeday, (file_time + 4), 12);
if (ft_strlen(file_st->timeday) != 12)
ft_memmove(&file_st->timeday[4], &file_st->timeday[3], 9);
if (((int)curr_time - (int)allstats->st_atime) > 15624439 ||
((int)curr_time - (int)allstats->st_atime) < 0)
ft_memmove(&file_st->timeday[7], &file_time[19], 5);
}
void ft_ctime(struct stat *allstats, t_finfo *file_st)
{
char *file_time;
time_t curr_time;
file_time = ctime((const time_t *)&allstats->st_ctime);
file_st->time_n = allstats->st_ctime;
time(&curr_time);
ft_strncat(file_st->timeday, (file_time + 4), 12);
if (ft_strlen(file_st->timeday) != 12)
ft_memmove(&file_st->timeday[4], &file_st->timeday[3], 9);
if (((int)curr_time - (int)allstats->st_ctime) > 15624439 ||
((int)curr_time - (int)allstats->st_ctime) < 0)
ft_memmove(&file_st->timeday[7], &file_time[19], 5);
}
void ft_file_time(struct stat *allstats, t_finfo *file_st, int flags)
{
char *file_time;
time_t curr_time;
if ((flags & MIN_U || flags & MAX_U) && !(flags & MIN_T))
{
if (flags & MIN_U)
ft_atime(allstats, file_st);
else
ft_ctime(allstats, file_st);
return ;
}
file_time = ctime((const time_t *)&allstats->st_mtime);
file_st->time_n = allstats->st_mtime;
time(&curr_time);
ft_strncat(file_st->timeday, (file_time + 4), 12);
if (ft_strlen(file_st->timeday) != 12)
ft_memmove(&file_st->timeday[4], &file_st->timeday[3], 9);
if (((int)curr_time - (int)allstats->st_mtime) > 15624439 ||
((int)curr_time - (int)allstats->st_mtime) < 0)
ft_memmove(&file_st->timeday[7], &file_time[19], 5);
}