summaryrefslogtreecommitdiff
path: root/open-vm-tools/lib/include/timeutil.h
blob: e90c0c62c60db84bc1dea9cf5dcb6c8e9f9eb3c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*********************************************************
 * Copyright (C) 1998 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation version 2.1 and no later version.
 *
 * 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 Lesser GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *********************************************************/

/*
 * timeutil.h --
 *
 *   Miscellaneous time related utility functions.
 *
 */

#ifndef _TIMEUTIL_H_
#define _TIMEUTIL_H_

#include <time.h>

#define INCLUDE_ALLOW_USERLEVEL
#include "includeCheck.h"

#include "vm_basic_types.h"
#include "vm_assert.h"


#define MAX_DAYSLEFT     4096

struct timeval;

#ifdef _WIN32
struct timespec {
   time_t tv_sec;
   long   tv_nsec;
};
#endif

/* Similar to a struct tm but with slightly less weird semantics. */
typedef struct TimeUtil_Date {
   unsigned int year;   /* e.g. 1970 */
   unsigned int month;  /* [1, 12] */
   unsigned int day;    /* [1, 31] */
   unsigned int hour;   /* [0, 23] */
   unsigned int minute; /* [0, 59] */
   unsigned int second; /* [0, 61] (for leap seconds) */
} TimeUtil_Date;

typedef struct TimeUtil_TimeOfDay {
   unsigned long seconds;
   unsigned long useconds;
} TimeUtil_TimeOfDay;

typedef struct TimeUtil_Expiration {
   /*
    * Does it expire?
    */

   Bool expires;

   /*
    * When does it expire? (valid only if 'expires' == TRUE)
    *
    * Note: TimeUtil_Expiration only uses the 'year', 'month'
    * and 'day' fields of 'when'.
    */

   TimeUtil_Date when;

   /*
    * Compute this once for all, to avoid problems when the current day changes
    * (valid only if 'expires' == TRUE).
    */

   unsigned int daysLeft;
} TimeUtil_Expiration;


time_t TimeUtil_MakeTime(const TimeUtil_Date *d); // IN

Bool TimeUtil_StringToDate(TimeUtil_Date *d,    // IN/OUT
                           char const *date);   // IN: 'YYYYMMDD' or 'YYYY/MM/DD' or 'YYYY-MM-DD'

Bool TimeUtil_DaysSubtract(TimeUtil_Date *d,  // IN/OUT
                           unsigned int nr);  // IN

int TimeUtil_DeltaDays(TimeUtil_Date const *left,   // IN
                       TimeUtil_Date const *right); // IN

void TimeUtil_DaysAdd(TimeUtil_Date *d, // IN/OUT
                      unsigned int nr); // IN

void TimeUtil_PopulateWithCurrent(Bool local,        // IN
                                  TimeUtil_Date *d); // OUT

void TimeUtil_GetTimeOfDay(TimeUtil_TimeOfDay *d); // OUT

unsigned int TimeUtil_DaysLeft(TimeUtil_Date const *d); // IN

Bool TimeUtil_ExpirationLowerThan(TimeUtil_Expiration const *left,   // IN
                                  TimeUtil_Expiration const *right); // IN

Bool TimeUtil_DateLowerThan(TimeUtil_Date const *left,   // IN
                            TimeUtil_Date const *right); // IN

void TimeUtil_ProductExpiration(TimeUtil_Expiration *e); // OUT

char * TimeUtil_GetTimeFormat(int64 utcTime,  // IN
                              Bool showDate,  // IN
                              Bool showTime); // IN

int TimeUtil_NtTimeToUnixTime(struct timespec *unixTime, // OUT
                              VmTimeType ntTime);        // IN

VmTimeType TimeUtil_UnixTimeToNtTime(struct timespec unixTime); // IN


#ifdef _WIN32
Bool TimeUtil_UTCTimeToSystemTime(const __time64_t utcTime,    // IN
                                  SYSTEMTIME *systemTime);     // OUT
#endif

int TimeUtil_GetLocalWindowsTimeZoneIndexAndName(char **ptzName);

time_t TimeUtil_SecondsSinceEpoch(TimeUtil_Date *d); // IN

#endif // _TIMEUTIL_H_