mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-26 17:28:13 +00:00
appveyor iterate / nlnet_timegm
This commit is contained in:
parent
c07cfd1e24
commit
4bdbbe8b28
5 changed files with 135 additions and 4 deletions
|
|
@ -57,6 +57,7 @@ DSL_OBJS = \
|
|||
TEST_ARGPARSE_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlrregex.c \
|
||||
|
|
@ -71,6 +72,7 @@ TEST_ARGPARSE_SRCS = \
|
|||
TEST_BYTE_READERS_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlrescape.c \
|
||||
|
|
@ -85,6 +87,7 @@ TEST_BYTE_READERS_SRCS = \
|
|||
TEST_LINE_READERS_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlrescape.c \
|
||||
|
|
@ -98,6 +101,7 @@ TEST_LINE_READERS_SRCS = \
|
|||
TEST_PEEK_FILE_READER_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlr_test_util.c \
|
||||
|
|
@ -110,6 +114,7 @@ TEST_PEEK_FILE_READER_SRCS = \
|
|||
TEST_LREC_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/context.c \
|
||||
|
|
@ -151,6 +156,7 @@ TEST_LREC_SRCS = \
|
|||
TEST_MULTIPLE_CONTAINERS_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/context.c \
|
||||
|
|
@ -200,6 +206,7 @@ TEST_MULTIPLE_CONTAINERS_SRCS = \
|
|||
TEST_MLHMMV_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlrdatetime.c \
|
||||
|
|
@ -220,6 +227,7 @@ TEST_MLRUTIL_SRCS = \
|
|||
lib/mlr_globals.c \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/string_builder.c \
|
||||
|
|
@ -229,6 +237,7 @@ TEST_MLRREGEX_SRCS = \
|
|||
lib/mlr_globals.c \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlrregex.c \
|
||||
|
|
@ -239,6 +248,7 @@ TEST_MLRREGEX_SRCS = \
|
|||
TEST_STRING_BUILDER_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlr_globals.c \
|
||||
|
|
@ -248,6 +258,7 @@ TEST_STRING_BUILDER_SRCS = \
|
|||
TEST_PARSE_TRIE_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlr_globals.c \
|
||||
|
|
@ -259,6 +270,7 @@ TEST_RVAL_EVALUATORS_SRCS = \
|
|||
lib/mlr_globals.c \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlrdatetime.c \
|
||||
|
|
@ -324,6 +336,7 @@ TEST_RVAL_EVALUATORS_SRCS = \
|
|||
TEST_JOIN_BUCKET_KEEPER_SRCS = \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/mlrescape.c \
|
||||
|
|
@ -372,6 +385,7 @@ EXPERIMENTAL_READER_SRCS = \
|
|||
lib/mlrutil.c \
|
||||
lib/mlrdatetime.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
lib/context.c \
|
||||
|
|
@ -390,6 +404,7 @@ EXPERIMENTAL_JSON_VG_MEM_SRCS = \
|
|||
lib/mlr_globals.c \
|
||||
lib/mlrutil.c \
|
||||
lib/mlr_arch.c \
|
||||
lib/nlnet_timegm.c \
|
||||
lib/netbsd_strptime.c \
|
||||
lib/mtrand.c \
|
||||
input/json_parser.c \
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ libmlr_la_SOURCES= free_flags.h \
|
|||
mlrutil.h \
|
||||
netbsd_strptime.c \
|
||||
netbsd_strptime.h \
|
||||
nlnet_timegm.c \
|
||||
nlnet_timegm.h \
|
||||
context.c \
|
||||
context.h \
|
||||
mtrand.c \
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "mlr_arch.h"
|
||||
#include "mlrutil.h"
|
||||
#include "netbsd_strptime.h"
|
||||
#include "nlnet_timegm.h"
|
||||
|
||||
// For some Linux distros, in spite of including time.h:
|
||||
char *strptime(const char *s, const char *format, struct tm *ptm);
|
||||
|
|
@ -42,12 +43,10 @@ char *mlr_arch_strptime(const char *s, const char *format, struct tm *ptm) {
|
|||
// See the GNU timegm manpage -- this is what it does.
|
||||
time_t mlr_arch_timegm(struct tm* ptm) {
|
||||
#ifdef MLR_ON_MSYS2
|
||||
return _mkgmtime(ptm);
|
||||
return nlnet_timegm(ptm);
|
||||
#else
|
||||
time_t ret;
|
||||
char* tz;
|
||||
|
||||
tz = getenv("TZ");
|
||||
char* tz = getenv("TZ");
|
||||
mlr_arch_setenv("TZ", "GMT0");
|
||||
tzset();
|
||||
ret = mktime(ptm);
|
||||
|
|
|
|||
74
c/lib/nlnet_timegm.c
Normal file
74
c/lib/nlnet_timegm.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* This software is open source.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the NLNET LABS nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/* Number of days per month (except for February in leap years). */
|
||||
static const int monoff[] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||
};
|
||||
|
||||
static int is_leap_year(int year) {
|
||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||
}
|
||||
|
||||
static int leap_days(int y1, int y2) {
|
||||
--y1;
|
||||
--y2;
|
||||
return (y2/4 - y1/4) - (y2/100 - y1/100) + (y2/400 - y1/400);
|
||||
}
|
||||
|
||||
/*
|
||||
* Code adapted from Python 2.4.1 sources (Lib/calendar.py).
|
||||
*/
|
||||
time_t nlnet_timegm(const struct tm *tm) {
|
||||
int year;
|
||||
time_t days;
|
||||
time_t hours;
|
||||
time_t minutes;
|
||||
time_t seconds;
|
||||
|
||||
year = 1900 + tm->tm_year;
|
||||
days = 365 * (year - 1970) + leap_days(1970, year);
|
||||
days += monoff[tm->tm_mon];
|
||||
|
||||
if (tm->tm_mon > 1 && is_leap_year(year))
|
||||
++days;
|
||||
days += tm->tm_mday - 1;
|
||||
|
||||
hours = days * 24 + tm->tm_hour;
|
||||
minutes = hours * 60 + tm->tm_min;
|
||||
seconds = minutes * 60 + tm->tm_sec;
|
||||
|
||||
return seconds;
|
||||
}
|
||||
41
c/lib/nlnet_timegm.h
Normal file
41
c/lib/nlnet_timegm.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
|
||||
*
|
||||
* This software is open source.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the NLNET LABS nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef NLNET_TIMEGM_H
|
||||
#define NLNET_TIMEGM_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
time_t nlnet_timegm(const struct tm *tm);
|
||||
|
||||
#endif // NLNET_TIMEGM_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue