mbgtools-lx  4.2.8
pcpsmktm.c
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: pcpsmktm.c 1.5 2017/07/05 08:05:11 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Function to convert PCPS_TIME to Unix time (seconds since 1970)
10  *
11  * -----------------------------------------------------------------------
12  * $Log: pcpsmktm.c $
13  * Revision 1.5 2017/07/05 08:05:11 martin
14  * Let pcps_mktime() return a 'time_t' instead of 'long', and made
15  * the PCPS_TIME pointer parameter 'const'.
16  * Added doxygen comments.
17  * Revision 1.4 2006/12/14 15:27:49 martin
18  * Include time.h.
19  * Revision 1.3 2006/08/22 09:10:03 martin
20  * Renamed function totalsec() to mbg_mktime() and moved it
21  * to a separate file mbgmktm.c.
22  * Revision 1.2 2001/08/14 11:58:08 MARTIN
23  * Included sys/time.h for time_t definition.
24  * Revision 1.1 2001/02/02 15:30:09 MARTIN
25  *
26  **************************************************************************/
27 
28 #define _PCPSMKTM
29  #include <pcpsmktm.h>
30 #undef _PCPSMKTM
31 
32 #include <mbgmktm.h>
33 
34 
35 
36 /*HDR*/
49 time_t pcps_mktime( const PCPS_TIME *tp )
50 {
51  time_t secs;
52  int year = tp->year;
53 
54  // Expand 2 digit year number (year of the century) to 4 digits
55  // including the century.
56  if ( year < 70 )
57  year += 100;
58 
59  // Plausibility checks are made by mbg_mktime().
60  secs = mbg_mktime( year, tp->month - 1, tp->mday - 1,
61  tp->hour, tp->min, tp->sec );
62 
63  // Convert to UTC if result is valid.
64  if ( secs != ( (time_t) -1 ) )
65  secs -= tp->offs_utc * 3600UL;
66 
67  return secs;
68 
69 } // pcps_mktime
70 
71 
72 
uint8_t year
year of the century, 0..99
Definition: pcpsdefs.h:1138
uint8_t mday
day of month, 0..31
Definition: pcpsdefs.h:1135
time_t mbg_mktime(int year, int month, int day, int hour, int min, int sec)
Compute a linear time_t value from broken down date and time.
Definition: mbgmktm.c:61
int8_t offs_utc
[hours], 0 if not _pcps_has_utc_offs
Definition: pcpsdefs.h:1142
uint8_t hour
hours, 0..23
Definition: pcpsdefs.h:1133
Definition: myutil.h:117
Local calendar date and time, plus sync status.
Definition: pcpsdefs.h:1128
uint8_t min
minutes, 0..59
Definition: pcpsdefs.h:1132
uint8_t month
month, 1..12
Definition: pcpsdefs.h:1137
time_t pcps_mktime(const PCPS_TIME *tp)
Compute a linear time_t value from PCPS_TIME.
Definition: pcpsmktm.c:49
uint8_t sec
seconds, 0..59, or 60 if leap second
Definition: pcpsdefs.h:1131