2009-02-05 21:28:18 +03:00
|
|
|
|
|
|
|
/** \file timefmt.h
|
2010-11-09 21:50:25 +03:00
|
|
|
* \brief Header: time formating functions
|
2009-02-05 21:28:18 +03:00
|
|
|
*/
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
#ifndef MC__UTIL_TIMEFMT_H
|
|
|
|
#define MC__UTIL_TIMEFMT_H
|
2009-01-10 13:53:20 +03:00
|
|
|
|
2010-02-02 14:06:32 +03:00
|
|
|
#include <sys/time.h>
|
2009-01-10 13:53:20 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** typedefs(not structures) and defined constants **********************************************/
|
|
|
|
|
2010-11-09 21:50:25 +03:00
|
|
|
#define MAX_I18NTIMELENGTH 20
|
|
|
|
#define MIN_I18NTIMELENGTH 10
|
|
|
|
#define STD_I18NTIMELENGTH 12
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
#define INVALID_TIME_TEXT "(invalid)"
|
2009-01-10 13:53:20 +03:00
|
|
|
|
|
|
|
/* safe localtime formatting - strftime()-using version */
|
2010-11-08 13:21:45 +03:00
|
|
|
#define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
|
|
|
|
{ \
|
|
|
|
struct tm *whentm; \
|
|
|
|
whentm = localtime(&when); \
|
|
|
|
if (whentm == NULL) \
|
|
|
|
{ \
|
|
|
|
strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
|
|
|
|
buffer[bufsize-1] = 0; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
strftime(buffer, bufsize, fmt, whentm); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
|
|
|
|
#define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
|
|
|
|
{ \
|
|
|
|
time_t __current_time; \
|
|
|
|
time(&__current_time); \
|
|
|
|
FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
|
2009-01-10 13:53:20 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** enums ***************************************************************************************/
|
|
|
|
|
|
|
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
|
|
|
|
|
|
|
/*** global variables defined in .c file *********************************************************/
|
|
|
|
|
2010-11-09 21:50:25 +03:00
|
|
|
extern char *user_recent_timeformat; /* time format string for recent dates */
|
|
|
|
extern char *user_old_timeformat; /* time format string for older dates */
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** declarations of public functions ************************************************************/
|
|
|
|
|
2010-11-09 21:50:25 +03:00
|
|
|
size_t i18n_checktimelength (void);
|
|
|
|
const char *file_date (time_t);
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** inline functions ****************************************************************************/
|
|
|
|
|
2010-11-09 21:50:25 +03:00
|
|
|
#endif /* MC__UTIL_TIMEFMT_H */
|