Add functions related to ticket #527

This commit is contained in:
Amin Ben Ramdhane 2019-04-25 11:31:02 +01:00
parent c3c0906ada
commit 0f143fd9d4
2 changed files with 34 additions and 0 deletions

View file

@ -1551,3 +1551,35 @@ void remove_elt_from_str_list(char **iface_list, char *ifname){
}
dmasprintf(iface_list, "%s", tmp);
}
int get_shift_time_time(int shift_time, char *local_time, int size)
{
time_t t_time;
struct tm *t_tm;
t_time = time(NULL) + shift_time;
t_tm = localtime(&t_time);
if (t_tm == NULL)
return -1;
if(strftime(local_time, size, "%FT%T%z", t_tm) == 0)
return -1;
local_time[25] = local_time[24];
local_time[24] = local_time[23];
local_time[22] = ':';
local_time[26] = '\0';
return 0;
}
int get_shift_time_shift(char *local_time, char *shift)
{
struct tm tm = {0};
strptime(local_time,"%FT%T", &tm);
sprintf(shift, "%u", (unsigned int)(mktime(&tm) - time(NULL)));
return 0;
}

View file

@ -196,5 +196,7 @@ int is_elt_exit_in_str_list(char *str_list, char *elt);
void add_elt_to_str_list(char **str_list, char *elt);
void remove_elt_from_str_list(char **iface_list, char *ifname);
struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* section_type, char*sect_name, char *opt_name, char* opt_value);
int get_shift_time_time(int shift_time, char *local_time, int size);
int get_shift_time_shift(char *local_time, char *shift);
#endif