added pretty_print_date_time function
This commit is contained in:
parent
8f1e0e7b1d
commit
0294dbf3e9
@ -1,4 +1,5 @@
|
|||||||
#include "date_time_handling.h"
|
#include "date_time_handling.h"
|
||||||
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -10,3 +11,16 @@ void get_date(char buffer[]) {
|
|||||||
strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local);
|
strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 20230823T194138 -> 2023-08-23 19:41:38
|
||||||
|
void pretty_print_date_time(char date_time[]) {
|
||||||
|
char *date = strtok(date_time, "T");
|
||||||
|
char *time = strtok(NULL, "T");
|
||||||
|
printf ("%c%c%c%c-", date[0], date[1], date[2], date[3]);
|
||||||
|
printf ("%c%c-", date[4], date[5]);
|
||||||
|
printf ("%c%c", date[6], date[7]);
|
||||||
|
if (time != NULL) {
|
||||||
|
printf (" %c%c:", time[0], time[1]);
|
||||||
|
printf ("%c%c:", time[2], time[3]);
|
||||||
|
printf ("%c%c", time[4], time[5]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,3 +2,4 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void get_date(char buffer[]);
|
void get_date(char buffer[]);
|
||||||
|
void pretty_print_date_time(char date_time[]);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "list_handling.h"
|
#include "list_handling.h"
|
||||||
|
#include "date_time_handling.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -46,8 +47,8 @@ void free_list(struct event *head)
|
|||||||
void print_upcoming(struct event *head, char current_date[]) {
|
void print_upcoming(struct event *head, char current_date[]) {
|
||||||
while (head != NULL) {
|
while (head != NULL) {
|
||||||
if (strcmp(head->date, current_date) >= 0) {
|
if (strcmp(head->date, current_date) >= 0) {
|
||||||
printf("%s\n", head->date);
|
pretty_print_date_time(head->date);
|
||||||
printf("%s\n", head->summary);
|
printf("\n%s\n", head->summary);
|
||||||
}
|
}
|
||||||
head = head->next;
|
head = head->next;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
static char current_date[] = "xxxxxxxxTxxxxxx";
|
static char current_date[] = "xxxxxxxxTxxxxxx";
|
||||||
get_date(current_date);
|
get_date(current_date);
|
||||||
printf ("Current date and time: %s\n\n", current_date);
|
printf ("Current date and time: ");
|
||||||
|
pretty_print_date_time(current_date);
|
||||||
|
printf ("\n");
|
||||||
|
|
||||||
char date[256] = "";
|
char date[256] = "";
|
||||||
char summary[256] = "";
|
char summary[256] = "";
|
||||||
@ -60,7 +62,6 @@ int main(int argc, char **argv) {
|
|||||||
memset(my_line, '\0', sizeof(my_line));
|
memset(my_line, '\0', sizeof(my_line));
|
||||||
}
|
}
|
||||||
|
|
||||||
//print_list(head);
|
|
||||||
print_upcoming(head, current_date);
|
print_upcoming(head, current_date);
|
||||||
|
|
||||||
free_list(head);
|
free_list(head);
|
||||||
|
Loading…
Reference in New Issue
Block a user