OPENSSL_GMTIME(3SSL)
π OPENSSL_GMTIME β¨
okay bestie, gather round, because this is the OPENSSL_GMTIME(3SSL) page and honestly? it's giving time-zone-girlie. it's the OpenSSL manual for a whole lil girlgroup of platform-agnostic OpenSSL time routines π°οΈπΈ β OPENSSL_gmtime, OPENSSL_gmtime_adj, OPENSSL_gmtime_diff, OPENSSL_timegm, OPENSSL_posix_to_tm and OPENSSL_tm_to_posix. six icons. one page. let's go π
π¦ SYNOPSIS π¦
#include <openssl/crypto.h>
struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result);
int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec);
int OPENSSL_gmtime_diff(int *pday, int *psec,
const struct tm *from, const struct tm *to);
#include <openssl/posix_time.h>
int OPENSSL_timegm(const struct tm *tm, time_t *out_time);
int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm);
int OPENSSL_tm_to_posix(struct tm t_tm, int64_t *out);
πΈ DESCRIPTION πΈ
so here's the tea, function by function π«:
OPENSSL_gmtime()β takes the Unix/Posix time you hand it intimerand drops it into theresultargument you provided.timerhas to be a value of the number of seconds relative to0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time, and no leap seconds allowed, bestie, and it must be in the range of the year0to9999inclusively.resultgets zeroed, and on success only the fieldstm_year,tm_mon,tm_mday,tm_hour,tm_min, andtm_secget updated inresult. only those six. the rest stay unbothered πOPENSSL_gmtime_adj()β adds the offsets hanging out inoffset_dayandoffset_sectotm. simple. slay.OPENSSL_gmtime_diff()β calculates the difference betweenfromandto. math era πOPENSSL_timegm()β converts a time structure in UTC time intminto atime_tvalue inout_time.OPENSSL_posix_to_tm()β converts aint64_tPOSIX time value intimeinto a broken out time value intm. same rules as before:timemust be a value of the number of seconds relative to0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time, no leap seconds, and it must be in the range of the year0to9999inclusively.tmwill be zeroed, and on success onlytm_year,tm_mon,tm_mday,tm_hour,tm_min, andtm_secget updated intm. the other fields are literally not invited πOPENSSL_tm_to_posix()β converts a time value between the years0and9999intminto a POSIX time value inout.
π NOTES π
real talk: these functions are meant for one very specific situation β when you're working withstruct tmvalues converted fromASN1_TIMEvalues. they are not intended for general purpose time conversions, and should not be used for other purposes. like, respect the niche, ok? π
when these functions take a struct tm as input, they only look at tm_year, tm_mon, tm_mday, tm_hour, tm_min, and tm_sec. every other field is ignored, ghosted, unseen. out of range values, including leap seconds, are not permitted π«
OPENSSL_gmtime_adj() converts tm into a days and seconds value, adds offset_day and offset_sec to the values, and then converts back into a struct tm specified by tm. it's a whole round trip, iconic honestly β¨
it is an error to call OPENSSL_gmtime() with result equal to NULL. the contents of the time_t given by timer are stored into the result. and calling with timer equal to NULL means use the current time β°
OPENSSL_gmtime_adj() converts tm into a days and seconds value, adds the offsets, then converts back into a struct tm specified by tm. (yes bestie it's in here twice, I don't make the rules, I just report them faithfully π)
OPENSSL_gmtime_diff() calculates the difference between the two struct tm structures from and to. the difference in days is placed into *pday, and the remaining seconds are placed to *psec. and the value in *psec will always be less than the number of seconds per day (86400). no overflow era. we stay within bounds here π
π RETURN VALUES π
OPENSSL_gmtime()returnsresulton success orNULLfor failure. it can fail if the input time is outside of the range of year0to9999.OPENSSL_posix_to_tm()returns1for success or0on failure. it can fail if the input time is outside of the range of year0to9999.OPENSSL_timegm()andOPENSSL_tm_to_posix()return1for success or0for failure.OpenSSL_timegm()can fail it the time is not representable in atime_t, and both may fail on invalid or out of range input in the inputtm.OPENSSL_gmtime_adj()andOPENSSL_gmtime_diff()return0on error, and1on success.
like, 1 good, 0 bad, NULL bad. got it? π«Ά
π BUGS π
not me having to expose the family drama but okay π OPENSSL_gmtime() and OPENSSL_timegm() are not platform-agnostic, because the platform time_t type might have limitations in its range. so they're a little limited, a little constrained, we love them anyway.
the fix? OPENSSL_posix_to_tm() and OPENSSL_tm_to_posix() provide similar functionality in a platform independent manner πβ¨
β HISTORY β
OPENSSL_gmtime()returnsNULLon error, orresulton success.OPENSSL_gmtime(),OPENSSL_gmtime_adj()andOPENSSL_gmtime_diff()have been in OpenSSL since1.0.0. they're basically elders, respect your ancestors πOPENSSL_timegm(),OPENSSL_posix_to_tm()andOPENSSL_tm_to_posix()were originally from BoringSSL and have been in OpenSSL since4.0.0. glow up from BoringSSL to OpenSSL, we love a crossover π
π COPYRIGHT π
Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay that's the whole page bestie, no cap, we ate π
mwah π this was OpenSSL version 4.0.3, dated 2026-09-29 β so go forth, convert your times, stay within year 0 to 9999, and do NOT touch those leap seconds π§β¨
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms