NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
timegm.c File Reference

For systems lacking timegm() More...

#include "config.h"
#include <stdbool.h>
#include <time.h>
+ Include dependency graph for timegm.c:

Go to the source code of this file.

Functions

static bool is_leap_year (int year)
 Is this a Leap Year? More...
 
static time_t tm_to_sec (struct tm *tm)
 Convert a time structure to number of seconds since the epoch. More...
 
time_t timegm (struct tm *tm)
 Convert struct tm to time_t seconds since epoch. More...
 

Detailed Description

For systems lacking timegm()

Authors
  • Claes Nästén

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file timegm.c.

Function Documentation

◆ is_leap_year()

static bool is_leap_year ( int  year)
static

Is this a Leap Year?

Parameters
yearYear
Return values
booltrue if it is a leap year

Definition at line 38 of file timegm.c.

39{
40 return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
41}
+ Here is the caller graph for this function:

◆ tm_to_sec()

static time_t tm_to_sec ( struct tm *  tm)
static

Convert a time structure to number of seconds since the epoch.

Parameters
tmTime structure
Return values
numSeconds since the epoch

Definition at line 48 of file timegm.c.

49{
50 time_t val = tm->tm_sec + (tm->tm_min * 60) + (tm->tm_hour * 3600) + (tm->tm_yday * 86400);
51
52 int year = 1900 + tm->tm_year;
53 for (int i = 1970; i < year; i++)
54 {
55 if (is_leap_year(i))
56 val += (366 * 86400);
57 else
58 val += (365 * 86400);
59 }
60
61 return val;
62}
static bool is_leap_year(int year)
Is this a Leap Year?
Definition: timegm.c:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ timegm()

time_t timegm ( struct tm *  tm)

Convert struct tm to time_t seconds since epoch.

Parameters
tmTime to convert to seconds since epoch
Return values
numSeconds since epoch

Definition at line 69 of file timegm.c.

70{
71 return tm_to_sec(tm);
72}
static time_t tm_to_sec(struct tm *tm)
Convert a time structure to number of seconds since the epoch.
Definition: timegm.c:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function: