From 0f143fd9d4c8e27d533d430bdd54d3db08669cb3 Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Thu, 25 Apr 2019 11:31:02 +0100 Subject: [PATCH] Add functions related to ticket #527 --- dm/dmcommon.c | 32 ++++++++++++++++++++++++++++++++ dm/dmcommon.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/dm/dmcommon.c b/dm/dmcommon.c index 1b646ac..8d77e2f 100644 --- a/dm/dmcommon.c +++ b/dm/dmcommon.c @@ -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; +} + diff --git a/dm/dmcommon.h b/dm/dmcommon.h index 7f13213..0dcdc54 100644 --- a/dm/dmcommon.h +++ b/dm/dmcommon.h @@ -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