strptime 0.2.0 → 0.2.5

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
- SHA1:
3
- metadata.gz: 40c47efa2978f1a82ef92004016f867410cd8e14
4
- data.tar.gz: e7c083dcfa17a354c0065bd714ed72db04711963
2
+ SHA256:
3
+ metadata.gz: a741d45e1df5db9edd3ff1e3bd235137328f2563ac874380ceafe5012440e546
4
+ data.tar.gz: 92e4185da32c8b5a078043f5e0a82e17068046a73447eedc8c155c00898f3537
5
5
  SHA512:
6
- metadata.gz: 0a0690297d03ae4875c0d0bf4b1df4d459ed424071cc294584857cc6103fea3236e2c7178c5252e8a0322caf601b109c1ee54ec6e190973de39e4321dbc06fc0
7
- data.tar.gz: ccaef9ed34774010e0de6059afd67314a70818890db1310cc2fa2dbbb60ebf94d99b7283ec2d69c767f14df142fc4740e1bb04afcca6c2a85af4e8e0223e304a
6
+ metadata.gz: 2ba79972b28e1dad5f8e545fe5c5ce4bbf709e4c3ae2769059dbe56ec7ccf39f31f4b70afa9a1891a0c75812c53baca3f006716cfd847fd384cafa38fc30494d
7
+ data.tar.gz: 369f41d9d60786c75090674a9e29ee16f6f16d0ea10007d47b9f558821d3b8537c40aacda0495b2a977acdbce191d53540890f51b83db68f5de0bf8a0272583c
@@ -9,10 +9,16 @@ rvm:
9
9
  - 2.2.4-clang
10
10
  - 2.3.0
11
11
  - 2.3.0-clang
12
+ - 2.4.2
13
+ - 2.4.2-clang
14
+ - 2.5.0
15
+ - 2.6.5
16
+ - 2.7.0
12
17
  - ruby-head
13
18
  matrix:
14
19
  allow_failures:
15
20
  - rvm: ruby-head
16
21
  before_install:
17
- - gem install bundler
22
+ # install bundler 1.17.3 is for ruby 2.0.0 - 2.2.4
23
+ - gem install bundler || gem install bundler -v 1.17.3
18
24
  cache: bundler
data/README.md CHANGED
@@ -26,6 +26,8 @@ Or install it yourself as:
26
26
 
27
27
  ## Usage
28
28
 
29
+ ### Strptime for time parsing
30
+
29
31
  ```ruby
30
32
  require 'strptime'
31
33
  parser = Strptime.new('%Y-%m-%dT%H:%M:%S%z')
@@ -33,6 +35,16 @@ parser.exec('2015-12-25T12:34:56+09') #=> 2015-12-25 12:34:56 +09:00
33
35
  parser.execi('2015-12-25T12:34:56+09') #=> 1451014496
34
36
  ```
35
37
 
38
+ ### Strftime for time formatting
39
+
40
+ ```ruby
41
+ require 'strptime'
42
+ now = Time.now
43
+ formatter = Strftime.new('%Y-%m-%dT%H:%M:%S.%L %z')
44
+ formatter.exec(now) # 2017-12-29T07:24:31.505 +0900
45
+ formatter.execi(now.to_i) # 2017-12-28T22:24:31.000 +0000
46
+ ```
47
+
36
48
  ## Contributing
37
49
 
38
50
  1. Fork it ( https://github.com/nurse/strptime/fork )
data/Rakefile CHANGED
@@ -31,6 +31,6 @@ namespace :build do
31
31
  desc 'Build gems for Windows per rake-compiler-dock'
32
32
  task :windows do
33
33
  require 'rake_compiler_dock'
34
- RakeCompilerDock.sh 'bundle && rake cross native gem RUBY_CC_VERSION=2.0.0:2.1.6:2.2.2:2.3.0:2.4.0'
34
+ RakeCompilerDock.sh 'bundle && rake cross native gem RUBY_CC_VERSION=2.0.0:2.1.6:2.2.2:2.3.0:2.4.0:2.5.0'
35
35
  end
36
36
  end
@@ -44,7 +44,9 @@ static ID id_gmtoff;
44
44
 
45
45
  #define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__)
46
46
 
47
-
47
+ static const char *month_names[] = {
48
+ "January", "February", "March", "April", "May", "June",
49
+ "July", "August", "September", "October", "November", "December"};
48
50
 
49
51
  static VALUE
50
52
  strftime_exec0(void **pc, VALUE fmt, struct timespec *tsp, int gmtoff, size_t result_length)
@@ -62,7 +64,7 @@ strftime_exec0(void **pc, VALUE fmt, struct timespec *tsp, int gmtoff, size_t re
62
64
  NULL, NULL, NULL, NULL,
63
65
  LABEL_PTR(Y), NULL, NULL, NULL,
64
66
  NULL, NULL, LABEL_PTR(_5f), LABEL_PTR(_60),
65
- NULL, NULL, NULL, LABEL_PTR(d),
67
+ NULL, LABEL_PTR(b), NULL, LABEL_PTR(d),
66
68
  LABEL_PTR(d), NULL, NULL, NULL,
67
69
  NULL, NULL, NULL, NULL,
68
70
  LABEL_PTR(m), NULL, NULL, NULL,
@@ -74,9 +76,10 @@ strftime_exec0(void **pc, VALUE fmt, struct timespec *tsp, int gmtoff, size_t re
74
76
  return Qnil;
75
77
  }
76
78
 
77
- result = rb_str_new(NULL, result_length);
79
+ result = rb_enc_str_new(NULL, result_length, rb_enc_get(fmt));
78
80
  p = RSTRING_PTR(result);
79
81
 
82
+ tsp->tv_sec += gmtoff;
80
83
  rb_gmtime_r(&tsp->tv_sec, &tm);
81
84
 
82
85
  INSN_DISPATCH();
@@ -150,6 +153,14 @@ strftime_exec0(void **pc, VALUE fmt, struct timespec *tsp, int gmtoff, size_t re
150
153
  ADD_PC(1);
151
154
  END_INSN(d)
152
155
  }
156
+ INSN_ENTRY(b)
157
+ {
158
+ const char *mon = month_names[tm.tm_mon];
159
+ memcpy(p, mon, 3);
160
+ p += 3;
161
+ ADD_PC(1);
162
+ END_INSN(b)
163
+ }
153
164
  INSN_ENTRY(m)
154
165
  {
155
166
  int mon = tm.tm_mon + 1;
@@ -250,6 +261,9 @@ strftime_compile(const char *fmt, size_t flen, size_t *rlenp)
250
261
  case 'd':
251
262
  rlen += 2;
252
263
  goto accept_format;
264
+ case 'b':
265
+ rlen += 3;
266
+ goto accept_format;
253
267
  case 'm':
254
268
  rlen += 2;
255
269
  goto accept_format;
@@ -490,5 +504,7 @@ Init_strftime(void)
490
504
  rb_define_method(rb_cStrftime, "exec", strftime_exec, 1);
491
505
  rb_define_method(rb_cStrftime, "execi", strftime_execi, 1);
492
506
  rb_define_method(rb_cStrftime, "source", strftime_source, 0);
507
+ #ifndef HAVE_RB_TIME_UTC_OFFSET
493
508
  id_gmtoff = rb_intern("gmtoff");
509
+ #endif
494
510
  }
@@ -366,7 +366,7 @@ strptime_exec0(void **pc, const char *fmt, const char *str, size_t slen,
366
366
  int r;
367
367
  size_t len;
368
368
  if (*p0 == 'z' || *p0 == 'Z') {
369
- gmtoff = 0;
369
+ gmtoff = INT_MAX-1;
370
370
  ADD_PC(1);
371
371
  END_INSN(z)
372
372
  }
@@ -1,3 +1,3 @@
1
1
  class Strptime
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
  spec.extensions = ["ext/strptime/extconf.rb"]
22
- spec.required_ruby_version = '~> 2.0'
22
+ spec.required_ruby_version = '>= 2.0'
23
23
 
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake"
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.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - NARUSE, Yui
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2020-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,7 +131,7 @@ require_paths:
131
131
  - lib
132
132
  required_ruby_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - "~>"
134
+ - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: '2.0'
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -140,8 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.6.13
143
+ rubygems_version: 3.1.2
145
144
  signing_key:
146
145
  specification_version: 4
147
146
  summary: a fast strptime/strftime engine.