Design Pattern Examples
Overview of object-oriented design patterns
makelocaltime.c File Reference

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

#include <time.h>
#include "makelocaltime.h"
Include dependency graph for makelocaltime.c:

Go to the source code of this file.

Functions

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

Detailed Description

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

Definition in file makelocaltime.c.

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().