source: murachi/esteidfirefoxplugin/common/esteid_time.c @ 56bf39a

Last change on this file since 56bf39a was 7d3ae3e, checked in by antonioaraujob <aaraujo@…>, 9 years ago

Agregados archivos fuentes del complemento esteidfirefoxplugin de Estonia para firmar electrónicamente un hash.

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * Estonian ID card plugin for web browsers
3 *
4 * Copyright (C) 2010-2011 Codeborne <info@codeborne.com>
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 *
20 */
21
22#include "esteid_time.h"
23#include "string.h"
24#include <stdio.h>
25
26#ifdef _WIN32
27
28#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
29  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
30#else
31  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
32#endif
33
34int gettimeofday(struct timeval *tv, struct timezone *tz) {
35  FILETIME ft;
36  unsigned __int64 tmpres = 0;
37  static int tzflag;
38 
39  if (NULL != tv) {
40    GetSystemTimeAsFileTime(&ft);
41 
42    tmpres |= ft.dwHighDateTime;
43    tmpres <<= 32;
44    tmpres |= ft.dwLowDateTime;
45 
46    tmpres /= 10;  /*convert into microseconds*/
47    tmpres -= DELTA_EPOCH_IN_MICROSECS; /*converting file time to unix epoch*/
48    tv->tv_sec = (long)(tmpres / 1000000UL);
49    tv->tv_usec = (long)(tmpres % 1000000UL);
50  }
51 
52  if (NULL != tz) {
53    if (!tzflag) {
54      _tzset();
55      tzflag++;
56    }
57    tz->tz_minuteswest = _timezone / 60;
58    tz->tz_dsttime = _daylight;
59  }
60  return 0;
61}
62
63#endif
64
65char* getDateFromDateTime(const char* dateTime) {
66        if(dateTime) {
67                char *returnBuffer = strdup(dateTime);
68                char* end = strchr(returnBuffer, ' ');
69                if(end) {
70                        *end = '\0';
71                }
72                return returnBuffer;
73        }
74        else {
75                return strdup("");
76        }
77}
78
79#ifdef _WIN32
80char* dateToString(FILETIME *filetime) {
81        SYSTEMTIME systemtime;
82        char buf[40] = {0};
83        FileTimeToSystemTime(filetime, &systemtime);
84        sprintf(buf, "%02d.%02d.%04d %02d:%02d:%02d", systemtime.wDay, systemtime.wMonth, systemtime.wYear, systemtime.wHour, systemtime.wMinute, systemtime.wSecond);
85        return strdup(buf);
86}
87#endif
Note: See TracBrowser for help on using the repository browser.