date 3.3.2 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75e3a4cb744689e80e55cc75831e2b6f13961ed10b2b0867a8a01d2ce33c28fc
4
- data.tar.gz: 2391f862cb91c7aed10383225fd6b6c0d8fe37cbd82cac038420ff2e6a6292c1
3
+ metadata.gz: 6ccf42407789dcdf94598ab68332e1860f4f2b5f5820d7b2b2bd8ae283088160
4
+ data.tar.gz: 988c7bded5cb20a4b68283216eeaaddf874a15765705919fe372bdeaf58d1c2a
5
5
  SHA512:
6
- metadata.gz: e1e7086f78e0951e84ba1a7dc349868d32a74dee4afc8bf5202e5d9d48f275feaa986b7968684b9bfafa027f25b6bee2e3b9fc68f6c6eaf261eeaac5565961fd
7
- data.tar.gz: 7e027f42df681fccf94500a543f19ca23a332f322db4d7ee10f533e1ff47d27ff28fb024131e93039d61eaca91f5386f3fc63edd6d2e00d3a25a10ca935dab98
6
+ metadata.gz: f99b7157afc55d925ffe6ea0f786ce4dc377a30786bb8045b71019db65cd056c83edbd4a979925060ed0daaae2f0cc71f19c04d0b89df53b6a39c70ad6005457
7
+ data.tar.gz: d4d955554151f00b3e0db05cf684d5e7c47655654fd3174aa3e1c67b14a9fa8696092219eac5e540ae9d9abe8c05b06e13bb4ff74c754c33b7e075e9b5498597
data/ext/date/date_core.c CHANGED
@@ -64,7 +64,8 @@ static VALUE datetime_initialize(int argc, VALUE *argv, VALUE self);
64
64
 
65
65
  #define RETURN_FALSE_UNLESS_NUMERIC(obj) if(!RTEST(rb_obj_is_kind_of((obj), rb_cNumeric))) return Qfalse
66
66
  inline static void
67
- check_numeric(VALUE obj, const char* field) {
67
+ check_numeric(VALUE obj, const char* field)
68
+ {
68
69
  if(!RTEST(rb_obj_is_kind_of(obj, rb_cNumeric))) {
69
70
  rb_raise(rb_eTypeError, "invalid %s (not numeric)", field);
70
71
  }
@@ -7437,7 +7438,8 @@ d_lite_jisx0301(VALUE self)
7437
7438
  }
7438
7439
 
7439
7440
  static VALUE
7440
- deconstruct_keys(VALUE self, VALUE keys, int is_datetime) {
7441
+ deconstruct_keys(VALUE self, VALUE keys, int is_datetime)
7442
+ {
7441
7443
  VALUE h = rb_hash_new();
7442
7444
  long i;
7443
7445
 
@@ -7520,7 +7522,8 @@ deconstruct_keys(VALUE self, VALUE keys, int is_datetime) {
7520
7522
  *
7521
7523
  */
7522
7524
  static VALUE
7523
- d_lite_deconstruct_keys(VALUE self, VALUE keys) {
7525
+ d_lite_deconstruct_keys(VALUE self, VALUE keys)
7526
+ {
7524
7527
  return deconstruct_keys(self, keys, /* is_datetime=false */ 0);
7525
7528
  }
7526
7529
 
@@ -8868,7 +8871,8 @@ dt_lite_jisx0301(int argc, VALUE *argv, VALUE self)
8868
8871
  *
8869
8872
  */
8870
8873
  static VALUE
8871
- dt_lite_deconstruct_keys(VALUE self, VALUE keys) {
8874
+ dt_lite_deconstruct_keys(VALUE self, VALUE keys)
8875
+ {
8872
8876
  return deconstruct_keys(self, keys, /* is_datetime=true */ 1);
8873
8877
  }
8874
8878
 
@@ -10,28 +10,15 @@
10
10
  static const char *day_names[] = {
11
11
  "Sunday", "Monday", "Tuesday", "Wednesday",
12
12
  "Thursday", "Friday", "Saturday",
13
- "Sun", "Mon", "Tue", "Wed",
14
- "Thu", "Fri", "Sat"
15
13
  };
14
+ static const int ABBREVIATED_DAY_NAME_LENGTH = 3;
16
15
 
17
16
  static const char *month_names[] = {
18
17
  "January", "February", "March", "April",
19
18
  "May", "June", "July", "August", "September",
20
19
  "October", "November", "December",
21
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
22
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
23
- };
24
-
25
- static const char *merid_names[] = {
26
- "am", "pm",
27
- "a.m.", "p.m."
28
- };
29
-
30
- static const char *extz_pats[] = {
31
- ":z",
32
- "::z",
33
- ":::z"
34
20
  };
21
+ static const int ABBREVIATED_MONTH_NAME_LENGTH = 3;
35
22
 
36
23
  #define sizeof_array(o) (sizeof o / sizeof o[0])
37
24
 
@@ -75,7 +62,7 @@ num_pattern_p(const char *s)
75
62
  #define NUM_PATTERN_P() num_pattern_p(&fmt[fi + 1])
76
63
 
77
64
  static long
78
- read_digits(const char *s, VALUE *n, size_t width)
65
+ read_digits(const char *s, size_t slen, VALUE *n, size_t width)
79
66
  {
80
67
  size_t l;
81
68
 
@@ -83,7 +70,7 @@ read_digits(const char *s, VALUE *n, size_t width)
83
70
  return 0;
84
71
 
85
72
  l = 0;
86
- while (ISDIGIT(s[l])) {
73
+ while (l < slen && ISDIGIT(s[l])) {
87
74
  if (++l == width) break;
88
75
  }
89
76
 
@@ -131,7 +118,7 @@ do { \
131
118
  #define READ_DIGITS(n,w) \
132
119
  do { \
133
120
  size_t l; \
134
- l = read_digits(&str[si], &n, w); \
121
+ l = read_digits(&str[si], slen - si, &n, w); \
135
122
  if (l == 0) \
136
123
  fail(); \
137
124
  si += l; \
@@ -161,6 +148,12 @@ do { \
161
148
 
162
149
  VALUE date_zone_to_diff(VALUE);
163
150
 
151
+ static inline int
152
+ head_match_p(size_t len, const char *name, const char *str, size_t slen, size_t si)
153
+ {
154
+ return slen - si >= len && strncasecmp(name, &str[si], len) == 0;
155
+ }
156
+
164
157
  static size_t
165
158
  date__strptime_internal(const char *str, size_t slen,
166
159
  const char *fmt, size_t flen, VALUE hash)
@@ -168,9 +161,18 @@ date__strptime_internal(const char *str, size_t slen,
168
161
  size_t si, fi;
169
162
  int c;
170
163
 
164
+ #define HEAD_MATCH_P(len, name) head_match_p(len, name, str, slen, si)
171
165
  si = fi = 0;
172
166
 
173
167
  while (fi < flen) {
168
+ if (isspace((unsigned char)fmt[fi])) {
169
+ while (si < slen && isspace((unsigned char)str[si]))
170
+ si++;
171
+ while (++fi < flen && isspace((unsigned char)fmt[fi]));
172
+ continue;
173
+ }
174
+
175
+ if (si >= slen) fail();
174
176
 
175
177
  switch (fmt[fi]) {
176
178
  case '%':
@@ -194,12 +196,11 @@ date__strptime_internal(const char *str, size_t slen,
194
196
  {
195
197
  int i;
196
198
 
197
- for (i = 0; i < (int)sizeof_array(extz_pats); i++)
198
- if (strncmp(extz_pats[i], &fmt[fi],
199
- strlen(extz_pats[i])) == 0) {
200
- fi += i;
201
- goto again;
202
- }
199
+ for (i = 1; i < 3 && fi + i < flen && fmt[fi+i] == ':'; ++i);
200
+ if (fmt[fi+i] == 'z') {
201
+ fi += i - 1;
202
+ goto again;
203
+ }
203
204
  fail();
204
205
  }
205
206
 
@@ -209,10 +210,12 @@ date__strptime_internal(const char *str, size_t slen,
209
210
  int i;
210
211
 
211
212
  for (i = 0; i < (int)sizeof_array(day_names); i++) {
212
- size_t l = strlen(day_names[i]);
213
- if (strncasecmp(day_names[i], &str[si], l) == 0) {
213
+ const char *day_name = day_names[i];
214
+ size_t l = strlen(day_name);
215
+ if (HEAD_MATCH_P(l, day_name) ||
216
+ HEAD_MATCH_P(l = ABBREVIATED_DAY_NAME_LENGTH, day_name)) {
214
217
  si += l;
215
- set_hash("wday", INT2FIX(i % 7));
218
+ set_hash("wday", INT2FIX(i));
216
219
  goto matched;
217
220
  }
218
221
  }
@@ -225,10 +228,12 @@ date__strptime_internal(const char *str, size_t slen,
225
228
  int i;
226
229
 
227
230
  for (i = 0; i < (int)sizeof_array(month_names); i++) {
228
- size_t l = strlen(month_names[i]);
229
- if (strncasecmp(month_names[i], &str[si], l) == 0) {
231
+ const char *month_name = month_names[i];
232
+ size_t l = strlen(month_name);
233
+ if (HEAD_MATCH_P(l, month_name) ||
234
+ HEAD_MATCH_P(l = ABBREVIATED_MONTH_NAME_LENGTH, month_name)) {
230
235
  si += l;
231
- set_hash("mon", INT2FIX((i % 12) + 1));
236
+ set_hash("mon", INT2FIX(i + 1));
232
237
  goto matched;
233
238
  }
234
239
  }
@@ -402,18 +407,19 @@ date__strptime_internal(const char *str, size_t slen,
402
407
 
403
408
  case 'P':
404
409
  case 'p':
410
+ if (slen - si < 2) fail();
405
411
  {
406
- int i;
407
-
408
- for (i = 0; i < 4; i++) {
409
- size_t l = strlen(merid_names[i]);
410
- if (strncasecmp(merid_names[i], &str[si], l) == 0) {
411
- si += l;
412
- set_hash("_merid", INT2FIX((i % 2) == 0 ? 0 : 12));
413
- goto matched;
414
- }
412
+ char c = str[si];
413
+ const int hour = (c == 'P' || c == 'p') ? 12 : 0;
414
+ if (!hour && !(c == 'A' || c == 'a')) fail();
415
+ if ((c = str[si+1]) == '.') {
416
+ if (slen - si < 4 || str[si+3] != '.') fail();
417
+ c = str[si += 2];
415
418
  }
416
- fail();
419
+ if (!(c == 'M' || c == 'm')) fail();
420
+ si += 2;
421
+ set_hash("_merid", INT2FIX(hour));
422
+ goto matched;
417
423
  }
418
424
 
419
425
  case 'Q':
@@ -587,7 +593,7 @@ date__strptime_internal(const char *str, size_t slen,
587
593
 
588
594
  b = rb_backref_get();
589
595
  rb_match_busy(b);
590
- m = f_match(pat, rb_usascii_str_new2(&str[si]));
596
+ m = f_match(pat, rb_usascii_str_new(&str[si], slen - si));
591
597
 
592
598
  if (!NIL_P(m)) {
593
599
  VALUE s, l, o;
@@ -619,22 +625,13 @@ date__strptime_internal(const char *str, size_t slen,
619
625
  if (str[si] != '%')
620
626
  fail();
621
627
  si++;
622
- if (fi < flen)
623
- if (str[si] != fmt[fi])
628
+ if (fi < flen) {
629
+ if (si >= slen || str[si] != fmt[fi])
624
630
  fail();
625
- si++;
631
+ si++;
632
+ }
626
633
  goto matched;
627
634
  }
628
- case ' ':
629
- case '\t':
630
- case '\n':
631
- case '\v':
632
- case '\f':
633
- case '\r':
634
- while (isspace((unsigned char)str[si]))
635
- si++;
636
- fi++;
637
- break;
638
635
  default:
639
636
  ordinal:
640
637
  if (str[si] != fmt[fi])
data/lib/date.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  require 'date_core'
5
5
 
6
6
  class Date
7
- VERSION = "3.3.2" # :nodoc:
7
+ VERSION = "3.3.3" # :nodoc:
8
8
 
9
9
  # call-seq:
10
10
  # infinite? -> false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.2
4
+ version: 3.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadayoshi Funaba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-16 00:00:00.000000000 Z
11
+ date: 2022-12-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A subclass of Object includes Comparable module for handling dates.
14
14
  email:
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubygems_version: 3.3.26
52
+ rubygems_version: 3.4.0.dev
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: A subclass of Object includes Comparable module for handling dates.