keisan 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/keisan/functions/default_registry.rb +3 -0
- data/lib/keisan/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 120e92a22f1bc276073eb006d158c63749382d71ace8c8bee3ea301590dc0f34
|
4
|
+
data.tar.gz: ae55746c285031ee69471663aa07930bb8b77cea65ad9df46764758d0908027f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6efb7ea75b6895ceb32b657edcccc924a50ee8d58d66eb0702e2b5bdf9d00a7f1718be17f663ce9140ac3563dcd61ea8fee47819f7e899052644909bbacc8f1
|
7
|
+
data.tar.gz: 33b991e75ca42b6e1039572da84ce0d10ec4f5461fdf04f0925e0bc5425b9d712d5b7ef76f5a65f7928e26fd4a4661016773bb8de90a66f8fd09c3f4cb0cff87
|
data/README.md
CHANGED
@@ -256,6 +256,7 @@ calculator.evaluate("range(1, 6).map(x, [x, x**2]).to_h")
|
|
256
256
|
Keisan supports date and time objects like in Ruby.
|
257
257
|
You create a date object using either the method `date` (either a string to be parsed, or year, month, day numerical arguments) or `today`.
|
258
258
|
They support methods `year`, `month`, `day`, `weekday`, `strftime`, and `to_time` to convert to a time object.
|
259
|
+
`epoch_days` computes the number of days since Unix epoch (Jan 1, 1970).
|
259
260
|
|
260
261
|
```ruby
|
261
262
|
calculator = Keisan::Calculator.new
|
@@ -266,10 +267,13 @@ calculator.evaluate("today() > date(2018, 11, 1)")
|
|
266
267
|
#=> true
|
267
268
|
calculator.evaluate("date('1999-12-31').to_time + 10")
|
268
269
|
#=> Time.new(1999, 12, 31, 0, 0, 10)
|
270
|
+
calculator.evaluate("date(1970, 1, 15).epoch_days")
|
271
|
+
#=> 14
|
269
272
|
```
|
270
273
|
|
271
274
|
Time objects are created using `time` (either a string to be parsed, or year, month, day, hour, minute, second arguments) or `now`.
|
272
275
|
They support methods `year`, `month`, `day`, `hour`, `minute`, `second`, `weekday`, `strftime`, and `to_date` to convert to a date object.
|
276
|
+
`epoch_seconds` computes the number of seconds since Unix epoch (00:00:00 on Jan 1, 1970).
|
273
277
|
|
274
278
|
```ruby
|
275
279
|
calculator = Keisan::Calculator.new
|
@@ -279,6 +283,8 @@ calculator.evaluate("time('2000-4-15 12:34:56').minute")
|
|
279
283
|
#=> 34
|
280
284
|
calculator.evaluate("time('5000-10-10 20:30:40').strftime('%b %d, %Y')")
|
281
285
|
#=> "Oct 10, 5000"
|
286
|
+
calculator.evaluate("time(1970, 1, 1, 2, 3, 4).epoch_seconds")
|
287
|
+
#=> 7384
|
282
288
|
```
|
283
289
|
|
284
290
|
##### Functional programming methods
|
@@ -147,6 +147,9 @@ module Keisan
|
|
147
147
|
|
148
148
|
registry.register!(:to_time, Proc.new {|d| d.to_time }, force: true)
|
149
149
|
registry.register!(:to_date, Proc.new {|t| t.to_date }, force: true)
|
150
|
+
|
151
|
+
registry.register!(:epoch_seconds, Proc.new {|d| d.to_time - Time.new(1970, 1, 1, 0, 0, 0) }, force: true)
|
152
|
+
registry.register!(:epoch_days, Proc.new {|t| t.to_date - Date.new(1970, 1, 1) }, force: true)
|
150
153
|
end
|
151
154
|
|
152
155
|
def self.register_date_time!(registry)
|
data/lib/keisan/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keisan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Locke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cmath
|