NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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?
 
static time_t tm_to_sec (struct tm *tm)
 Convert a time structure to number of seconds since the epoch.
 
time_t timegm (struct tm *tm)
 Convert struct tm to time_t seconds since epoch.
 

Detailed Description

For systems lacking timegm()

Authors
  • Claes Nästén
  • Richard Russon

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
trueIt's a leap year

Definition at line 39 of file timegm.c.

40{
41 return ((year % 400) == 0) || (((year % 4) == 0) && ((year % 100) != 0));
42}
+ 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 49 of file timegm.c.

50{
51 time_t val = tm->tm_sec + (tm->tm_min * 60) + (tm->tm_hour * 3600) + (tm->tm_yday * 86400);
52
53 int year = 1900 + tm->tm_year;
54 for (int i = 1970; i < year; i++)
55 {
56 if (is_leap_year(i))
57 val += (366 * 86400);
58 else
59 val += (365 * 86400);
60 }
61
62 return val;
63}
static bool is_leap_year(int year)
Is this a Leap Year?
Definition: timegm.c:39
+ 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 70 of file timegm.c.

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