Skip to content

Commit fd23e98

Browse files
committed
Move timegm implementation out of Taskwarrior into libshared
The reimplementation of timegm is actually only used internally in libshared
1 parent 8ad3646 commit fd23e98

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set (PACKAGE_VERSION "${VERSION}")
2222
set (PACKAGE_STRING "${PACKAGE} ${VERSION}")
2323

2424
check_function_exists(strlcpy HAVE_STRLCPY)
25+
check_function_exists(timegm HAVE_TIMEGM)
2526

2627
message ("-- Configuring cmake.h")
2728
configure_file (

cmake.h.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
/* Found strlcpy() */
3434
#cmakedefine HAVE_STRLCPY
3535

36+
/* Found timegm(struct tm*) */
37+
#cmakedefine HAVE_TIMEGM
38+
3639
/* Functions */
3740
#cmakedefine HAVE_GET_CURRENT_DIR_NAME
38-
#cmakedefine HAVE_TIMEGM
3941
#cmakedefine HAVE_UUID_UNPARSE_LOWER
4042

src/Datetime.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,23 @@ bool Datetime::validate ()
31193119
return true;
31203120
}
31213121

3122+
#ifndef HAVE_TIMEGM
3123+
time_t Datetime::timegm(struct tm* tm) {
3124+
time_t ret;
3125+
char* tz;
3126+
tz = getenv("TZ");
3127+
setenv("TZ", "UTC", 1);
3128+
tzset();
3129+
ret = mktime(tm);
3130+
if (tz)
3131+
setenv("TZ", tz, 1);
3132+
else
3133+
unsetenv("TZ");
3134+
tzset();
3135+
return ret;
3136+
}
3137+
#endif
3138+
31223139
////////////////////////////////////////////////////////////////////////////////
31233140
// int tm_sec; seconds (0 - 60)
31243141
// int tm_min; minutes (0 - 59)

src/Datetime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ class Datetime
201201
bool validate ();
202202
void resolve ();
203203

204+
#ifndef HAVE_TIMEGM
205+
time_t timegm(struct tm*);
206+
#endif
207+
204208
public:
205209
int _year {0};
206210
int _month {0};

0 commit comments

Comments
 (0)