strptime 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/appveyor.yml +1 -3
- data/ext/strptime/extconf.rb +2 -1
- data/ext/strptime/ruby_time.c +22 -9
- data/ext/strptime/strptime.c +12 -33
- data/ext/strptime/strptime.h +6 -2
- data/lib/strptime/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0aeb413a53bd63240a359b0343bf5e3d3204bdf
|
4
|
+
data.tar.gz: 358990f23e0e9885c2e20f1dc2301c772bb3bb70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10d2cb9ec99244fd81d54de6d8a5b6e0a8fb4218dbd22716f95c2df586eedbb50309fba82604f61aaa0232f523145bd4e115652e5de373828c5aee7ce014d5ef
|
7
|
+
data.tar.gz: a57fe751a496f587dda41fc500c49a2433a46b744d8a79819804b71204d805d2796a2e3024ffad54e3aa3572ac639f6ad8dcd734385e7915c938a23540ef77e0
|
data/.travis.yml
CHANGED
data/appveyor.yml
CHANGED
data/ext/strptime/extconf.rb
CHANGED
data/ext/strptime/ruby_time.c
CHANGED
@@ -20,7 +20,8 @@
|
|
20
20
|
typedef uint64_t WIDEVALUE;
|
21
21
|
typedef WIDEVALUE wideval_t;
|
22
22
|
|
23
|
-
#
|
23
|
+
#ifndef HAVE_RB_TIME_TIMESPEC_NEW
|
24
|
+
# if defined(PACKED_STRUCT_UNALIGNED) /* 2.2 */
|
24
25
|
PACKED_STRUCT_UNALIGNED(struct vtm {
|
25
26
|
VALUE year; /* 2000 for example. Integer. */
|
26
27
|
VALUE subsecx; /* 0 <= subsecx < TIME_SCALE. possibly Rational. */
|
@@ -41,7 +42,7 @@ PACKED_STRUCT_UNALIGNED(struct time_object {
|
|
41
42
|
uint8_t gmt : 3; /* 0:utc 1:localtime 2:fixoff 3:init */
|
42
43
|
uint8_t tm_got : 1;
|
43
44
|
});
|
44
|
-
#else
|
45
|
+
# else /* 2.0.0~2.1 */
|
45
46
|
struct vtm {
|
46
47
|
VALUE year; /* 2000 for example. Integer. */
|
47
48
|
int mon; /* 1..12 */
|
@@ -62,15 +63,13 @@ struct time_object {
|
|
62
63
|
int gmt; /* 0:utc 1:localtime 2:fixoff */
|
63
64
|
int tm_got;
|
64
65
|
};
|
65
|
-
#endif
|
66
|
+
# endif
|
66
67
|
|
67
68
|
VALUE
|
68
|
-
|
69
|
-
VALUE
|
70
|
-
rbtime_timespec_new(const struct timespec *ts, int offset)
|
69
|
+
rb_time_timespec_new(const struct timespec *ts, int offset)
|
71
70
|
{
|
72
71
|
VALUE obj = rb_time_nano_new(ts->tv_sec, ts->tv_nsec);
|
73
|
-
if (offset) {
|
72
|
+
if (-86400 < offset && offset < 86400) { /* fixoff */
|
74
73
|
struct time_object *tobj;
|
75
74
|
tobj = DATA_PTR(obj);
|
76
75
|
tobj->tm_got = 0;
|
@@ -78,12 +77,25 @@ rbtime_timespec_new(const struct timespec *ts, int offset)
|
|
78
77
|
tobj->vtm.utc_offset = INT2FIX(offset);
|
79
78
|
tobj->vtm.zone = NULL;
|
80
79
|
}
|
80
|
+
else if (offset == INT_MAX) { /* localtime */
|
81
|
+
}
|
82
|
+
else if (offset == INT_MAX-1) { /* UTC */
|
83
|
+
struct time_object *tobj;
|
84
|
+
tobj = DATA_PTR(obj);
|
85
|
+
tobj->tm_got = 0;
|
86
|
+
tobj->gmt = 1;
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
rb_raise(rb_eArgError, "utc_offset out of range");
|
90
|
+
}
|
91
|
+
|
81
92
|
return obj;
|
82
93
|
}
|
94
|
+
#endif
|
83
95
|
|
84
|
-
|
96
|
+
#ifndef RB_TIMESPEC_NOW
|
85
97
|
void
|
86
|
-
|
98
|
+
rb_timespec_now(struct timespec *ts)
|
87
99
|
{
|
88
100
|
#ifdef HAVE_CLOCK_GETTIME
|
89
101
|
if (clock_gettime(CLOCK_REALTIME, ts) == -1) {
|
@@ -100,6 +112,7 @@ timespec_now(struct timespec *ts)
|
|
100
112
|
}
|
101
113
|
#endif
|
102
114
|
}
|
115
|
+
#endif
|
103
116
|
|
104
117
|
/* localtime_with_gmtoff_zone */
|
105
118
|
#ifdef HAVE_GMTIME_R
|
data/ext/strptime/strptime.c
CHANGED
@@ -365,7 +365,7 @@ strptime_exec0(void **pc, const char *fmt, const char *str, size_t slen,
|
|
365
365
|
const char *p0 = str + si;
|
366
366
|
int r;
|
367
367
|
size_t len;
|
368
|
-
if (*p0 == 'z') {
|
368
|
+
if (*p0 == 'z' || *p0 == 'Z') {
|
369
369
|
gmtoff = 0;
|
370
370
|
ADD_PC(1);
|
371
371
|
END_INSN(z)
|
@@ -420,9 +420,10 @@ strptime_exec0(void **pc, const char *fmt, const char *str, size_t slen,
|
|
420
420
|
struct timespec ts;
|
421
421
|
struct tm tm;
|
422
422
|
time_t t;
|
423
|
+
int gmt = gmtoff >= INT_MAX-1 ? INT_MAX-gmtoff : 2;
|
423
424
|
|
424
425
|
/* get current time with timezone */
|
425
|
-
|
426
|
+
rb_timespec_now(&ts);
|
426
427
|
{
|
427
428
|
static time_t ct;
|
428
429
|
static struct tm ctm;
|
@@ -436,6 +437,9 @@ strptime_exec0(void **pc, const char *fmt, const char *str, size_t slen,
|
|
436
437
|
if (gmtoff == INT_MAX) {
|
437
438
|
gmtoff = localoff;
|
438
439
|
}
|
440
|
+
else if (gmtoff == INT_MAX-1) {
|
441
|
+
gmtoff = 0;
|
442
|
+
}
|
439
443
|
if (gmtoff != ctmoff) {
|
440
444
|
tm_add_offset(&ctm, gmtoff - ctmoff);
|
441
445
|
ctmoff = gmtoff;
|
@@ -469,7 +473,8 @@ strptime_exec0(void **pc, const char *fmt, const char *str, size_t slen,
|
|
469
473
|
if (sec != -1) tm.tm_sec = sec;
|
470
474
|
}
|
471
475
|
|
472
|
-
t = timegm_noleapsecond(&tm)
|
476
|
+
t = timegm_noleapsecond(&tm);
|
477
|
+
if (gmt != 1) t -= gmtoff;
|
473
478
|
tsp->tv_sec = t;
|
474
479
|
tsp->tv_nsec = nsec;
|
475
480
|
*gmtoffp = gmtoff;
|
@@ -658,32 +663,6 @@ strptime_init_copy(VALUE copy, VALUE self)
|
|
658
663
|
return copy;
|
659
664
|
}
|
660
665
|
|
661
|
-
typedef uint64_t WIDEVALUE;
|
662
|
-
typedef WIDEVALUE wideval_t;
|
663
|
-
#ifndef PACKED_STRUCT_UNALIGNED
|
664
|
-
#define PACKED_STRUCT_UNALIGNED(x) x
|
665
|
-
#endif
|
666
|
-
PACKED_STRUCT_UNALIGNED(struct vtm {
|
667
|
-
VALUE year; /* 2000 for example. Integer. */
|
668
|
-
VALUE subsecx; /* 0 <= subsecx < TIME_SCALE. possibly Rational. */
|
669
|
-
VALUE utc_offset; /* -3600 as -01:00 for example. possibly Rational. */
|
670
|
-
const char *zone; /* "JST", "EST", "EDT", etc. */
|
671
|
-
uint16_t yday : 9; /* 1..366 */
|
672
|
-
uint8_t mon : 4; /* 1..12 */
|
673
|
-
uint8_t mday : 5; /* 1..31 */
|
674
|
-
uint8_t hour : 5; /* 0..23 */
|
675
|
-
uint8_t min : 6; /* 0..59 */
|
676
|
-
uint8_t sec : 6; /* 0..60 */
|
677
|
-
uint8_t wday : 3; /* 0:Sunday, 1:Monday, ..., 6:Saturday 7:init */
|
678
|
-
uint8_t isdst : 2; /* 0:StandardTime 1:DayLightSavingTime 3:init */
|
679
|
-
});
|
680
|
-
PACKED_STRUCT_UNALIGNED(struct time_object {
|
681
|
-
wideval_t timew; /* time_t value * TIME_SCALE. possibly Rational. */
|
682
|
-
struct vtm vtm;
|
683
|
-
uint8_t gmt : 3; /* 0:utc 1:localtime 2:fixoff 3:init */
|
684
|
-
uint8_t tm_got : 1;
|
685
|
-
});
|
686
|
-
|
687
666
|
/*
|
688
667
|
* @overload exec(str)
|
689
668
|
* @param str [String] string to parse
|
@@ -696,15 +675,15 @@ static VALUE
|
|
696
675
|
strptime_exec(VALUE self, VALUE str)
|
697
676
|
{
|
698
677
|
struct strptime_object *tobj;
|
699
|
-
int r, gmtoff =
|
678
|
+
int r, gmtoff = INT_MAX;
|
679
|
+
struct timespec ts;
|
700
680
|
StringValue(str);
|
701
681
|
GetStrptimeval(self, tobj);
|
702
|
-
struct timespec ts;
|
703
682
|
|
704
683
|
r = strptime_exec0(tobj->isns, RSTRING_PTR(tobj->fmt), RSTRING_PTR(str),
|
705
684
|
RSTRING_LEN(str), &ts, &gmtoff);
|
706
685
|
if (r) rb_raise(rb_eArgError, "string doesn't match");
|
707
|
-
return
|
686
|
+
return rb_time_timespec_new(&ts, gmtoff);
|
708
687
|
}
|
709
688
|
|
710
689
|
/*
|
@@ -719,7 +698,7 @@ strptime_execi(VALUE self, VALUE str)
|
|
719
698
|
{
|
720
699
|
struct strptime_object *tobj;
|
721
700
|
struct timespec ts;
|
722
|
-
int r, gmtoff =
|
701
|
+
int r, gmtoff = INT_MAX;
|
723
702
|
StringValue(str);
|
724
703
|
GetStrptimeval(self, tobj);
|
725
704
|
|
data/ext/strptime/strptime.h
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
#define STRPTIME_H 1
|
3
3
|
|
4
4
|
#include "ruby.h"
|
5
|
-
|
5
|
+
# ifndef HAVE_RB_TIME_TIMESPEC_NEW
|
6
|
+
VALUE rb_time_timespec_new(const struct timespec *ts, int offset);
|
7
|
+
# endif
|
6
8
|
struct tm * localtime_with_gmtoff_zone(const time_t *t, struct tm *result, long *gmtoff, const char **zone);
|
7
|
-
|
9
|
+
# ifndef HAVE_RB_TIMESPEC_NOW
|
10
|
+
void rb_timespec_now(struct timespec *ts);
|
11
|
+
# endif
|
8
12
|
time_t timegm_noleapsecond(struct tm *tm);
|
9
13
|
void tm_add_offset(struct tm *tm, long diff);
|
10
14
|
|
data/lib/strptime/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strptime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NARUSE, Yui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.4.5
|
143
|
+
rubygems_version: 2.4.5.1
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: a fast strptime engine.
|