strptime 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/ext/strptime/strftime.c +15 -2
- data/lib/strptime/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c987792cc3f05d75ef1dc89a1c847f9bac19403
|
4
|
+
data.tar.gz: aa8a4b780e4030c46476a4cb37d892d6764ceca4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9917747c59e9bc034bc19827c7974644f0a63224e78a968b92f926c4f1656246639f9b014f0e51a5f12ca5f6dbfc6aa1939e68a9128749d90e734131476a7585
|
7
|
+
data.tar.gz: 9a7d916b760bd9e7a61192db14c1ef5a99385a61d3a515d41caae8cb7d1d9c4e79ce4904a3fb6f1344eeb767c870821d045e04350393b34638f264241847b17a
|
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/ext/strptime/strftime.c
CHANGED
@@ -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,
|
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,
|
@@ -151,6 +153,14 @@ strftime_exec0(void **pc, VALUE fmt, struct timespec *tsp, int gmtoff, size_t re
|
|
151
153
|
ADD_PC(1);
|
152
154
|
END_INSN(d)
|
153
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
|
+
}
|
154
164
|
INSN_ENTRY(m)
|
155
165
|
{
|
156
166
|
int mon = tm.tm_mon + 1;
|
@@ -251,6 +261,9 @@ strftime_compile(const char *fmt, size_t flen, size_t *rlenp)
|
|
251
261
|
case 'd':
|
252
262
|
rlen += 2;
|
253
263
|
goto accept_format;
|
264
|
+
case 'b':
|
265
|
+
rlen += 3;
|
266
|
+
goto accept_format;
|
254
267
|
case 'm':
|
255
268
|
rlen += 2;
|
256
269
|
goto accept_format;
|
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NARUSE, Yui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|