Design Pattern Examples
Overview of object-oriented design patterns
helpers/makelocaltime.h File Reference

Declaration of the makelocaltime() function to convert a time_t to a struct tm containing the local time. More...

#include <time.h>
Include dependency graph for helpers/makelocaltime.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __MAKELOCALTIME_H__
 

Functions

struct tm * makelocaltime (const time_t *time, struct tm *timestruct)
 Convert the given time to local time.
 

Detailed Description

Declaration of the makelocaltime() function to convert a time_t to a struct tm containing the local time.

Definition in file helpers/makelocaltime.h.

Macro Definition Documentation

◆ __MAKELOCALTIME_H__

#define __MAKELOCALTIME_H__

Definition at line 8 of file helpers/makelocaltime.h.

Function Documentation

◆ makelocaltime()

struct tm * makelocaltime ( const time_t *  time,
struct tm *  timestruct 
)

Convert the given time to local time.

Hides the differences between multiple C library implementations.

Parameters
timePointer to the time_t object representing the time to convert.
timestructPointer to a struct tm in which to put the results of converting to local time.
Returns
Returns the pointer to the struct tm if all is well; otherwise, returns NULL, indicating an error (runtime constraint violation or a failure to convert the specified time to local calendar time).

This is an example of a function acting as an adapter (see Adapter Pattern). The rest of the program just wants to convert a time stamp to local time and doesn't want to know about the differences between implementations of the C library.

Definition at line 13 of file makelocaltime.c.

Referenced by datetime_to_string().