mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-13 17:27:21 -05:00
Fix and Consolidate Date and Time Functions (WIP); #255
This commit is contained in:
71
src/dsd_time.c
Normal file
71
src/dsd_time.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*-------------------------------------------------------------------------------
|
||||
* dsd_time.c
|
||||
* Time and Date Functions
|
||||
*
|
||||
* LWVMOBILE
|
||||
* 2024-04 DSD-FME Florida Man Edition
|
||||
*-----------------------------------------------------------------------------*/
|
||||
|
||||
//TODO: Make sure everything still works as intended, no random crashes on free (timestr)
|
||||
//make sure no other loose or random time functions embedded in other files or functions, etc
|
||||
|
||||
#include "dsd.h"
|
||||
|
||||
//get hhmmss timestamp no colon (file operations)
|
||||
char * getTime()
|
||||
{
|
||||
char * curr = (char *) malloc(9);
|
||||
time_t t = time(NULL);
|
||||
struct tm * ptm = localtime(& t);
|
||||
sprintf(curr,"%02d%02d%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
||||
return curr;
|
||||
}
|
||||
|
||||
//get hh:mm:ss timestamp with colon (Ncurses Display)
|
||||
char * getTimeC()
|
||||
{
|
||||
char * curr = (char *) malloc(9);
|
||||
time_t t = time(NULL);
|
||||
struct tm * ptm = localtime(& t);
|
||||
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
||||
return curr;
|
||||
}
|
||||
|
||||
//get hh:mm:ss timestamp with colon (Ncurses Display)
|
||||
char * getTimeN(time_t t)
|
||||
{
|
||||
char * curr = (char *) malloc(9);
|
||||
struct tm * ptm = localtime(& t);
|
||||
sprintf(curr, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
|
||||
return curr;
|
||||
}
|
||||
|
||||
//get YYYYMMDD without hyphen (file operations)
|
||||
char * getDate()
|
||||
{
|
||||
char * curr = (char *) malloc(25);
|
||||
time_t t = time(NULL);
|
||||
struct tm * ptm = localtime(& t);
|
||||
sprintf(curr,"%04d%02d%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
|
||||
return curr;
|
||||
}
|
||||
|
||||
//get YYYY-MM-DD with hyphen (Ncurses Display)
|
||||
char * getDateH()
|
||||
{
|
||||
char * curr = (char *) malloc(27);
|
||||
time_t t = time(NULL);
|
||||
struct tm * ptm = localtime(& t);
|
||||
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
|
||||
return curr;
|
||||
}
|
||||
|
||||
//get YYYY-MM-DD with hyphen (Ncurses Call History)
|
||||
char * getDateN(time_t t)
|
||||
{
|
||||
char * curr = (char *) malloc(27);
|
||||
struct tm * ptm = localtime(& t);
|
||||
sprintf(curr, "%04d-%02d-%02d", ptm->tm_year+1900, ptm->tm_mon+1, ptm->tm_mday);
|
||||
return curr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user