summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/XTimeUtils.h
blob: 91cda40305027e56483e3c69c343c9e043a9b528 (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
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include <chrono>
#include <string>
#include <thread>

#if !defined(TARGET_WINDOWS)
#include "PlatformDefs.h"
#else
// This is needed, a forward declaration of FILETIME
// breaks everything
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#endif

namespace KODI
{
namespace TIME
{
struct SystemTime
{
  unsigned short year;
  unsigned short month;
  unsigned short dayOfWeek;
  unsigned short day;
  unsigned short hour;
  unsigned short minute;
  unsigned short second;
  unsigned short milliseconds;
};

struct TimeZoneInformation
{
  long bias;
  std::string standardName;
  SystemTime standardDate;
  long standardBias;
  std::string daylightName;
  SystemTime daylightDate;
  long daylightBias;
};

constexpr int KODI_TIME_ZONE_ID_INVALID{-1};
constexpr int KODI_TIME_ZONE_ID_UNKNOWN{0};
constexpr int KODI_TIME_ZONE_ID_STANDARD{1};
constexpr int KODI_TIME_ZONE_ID_DAYLIGHT{2};

struct FileTime
{
  unsigned int lowDateTime;
  unsigned int highDateTime;
};

void GetLocalTime(SystemTime* systemTime);
uint32_t GetTimeZoneInformation(TimeZoneInformation* timeZoneInformation);

template<typename Rep, typename Period>
void Sleep(std::chrono::duration<Rep, Period> duration)
{
  if (duration == std::chrono::duration<Rep, Period>::zero())
  {
    std::this_thread::yield();
    return;
  }

  std::this_thread::sleep_for(duration);
}

int FileTimeToLocalFileTime(const FileTime* fileTime, FileTime* localFileTime);
int SystemTimeToFileTime(const SystemTime* systemTime, FileTime* fileTime);
long CompareFileTime(const FileTime* fileTime1, const FileTime* fileTime2);
int FileTimeToSystemTime(const FileTime* fileTime, SystemTime* systemTime);
int LocalFileTimeToFileTime(const FileTime* LocalFileTime, FileTime* fileTime);

int FileTimeToTimeT(const FileTime* localFileTime, time_t* pTimeT);
int TimeTToFileTime(time_t timeT, FileTime* localFileTime);
} // namespace TIME
} // namespace KODI