datet 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/datet.gemspec +2 -2
- data/lib/datet.rb +26 -0
- data/spec/datet_spec.rb +16 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.17
|
data/datet.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datet}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.17"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kasper Johansen"]
|
12
|
-
s.date = %q{2012-08-
|
12
|
+
s.date = %q{2012-08-22}
|
13
13
|
s.description = %q{A framework for handeling date- and time-related stuff in Ruby.}
|
14
14
|
s.email = %q{k@spernj.org}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/datet.rb
CHANGED
@@ -1520,4 +1520,30 @@ class Datet
|
|
1520
1520
|
#Return the replaced string.
|
1521
1521
|
return res
|
1522
1522
|
end
|
1523
|
+
|
1524
|
+
#Updates the date-data from a given string.
|
1525
|
+
#===Examples
|
1526
|
+
# datet.dbstr #=> '2012-09-05 01:00:00'
|
1527
|
+
# datet.update_from_str("10:00")
|
1528
|
+
# datet.dbstr #=> '2012-09-05 10:00:00'
|
1529
|
+
# datet.update_from_str("1/2")
|
1530
|
+
# datet.dbstr #=> '2012-02-01 10:00:00'
|
1531
|
+
def update_from_str(str)
|
1532
|
+
str = str.to_s
|
1533
|
+
|
1534
|
+
if match = str.match(/^\s*(\d+)\s*:\s*(\d+)\s*$/)
|
1535
|
+
self.hour = match[1].to_i
|
1536
|
+
self.min = match[2].to_i
|
1537
|
+
elsif match = str.match(/^\s*(\d+)\s*\/\s*(\d+)(\s*|\s+(\d+)\s*)$/)
|
1538
|
+
self.day = match[1].to_i
|
1539
|
+
self.month = match[2].to_i
|
1540
|
+
|
1541
|
+
year_no = match[4].to_i
|
1542
|
+
self.year = year_no if year_no > 0
|
1543
|
+
else
|
1544
|
+
raise "Could not understand given string: '#{str}'."
|
1545
|
+
end
|
1546
|
+
|
1547
|
+
return self
|
1548
|
+
end
|
1523
1549
|
end
|
data/spec/datet_spec.rb
CHANGED
@@ -503,4 +503,20 @@ describe "Datet" do
|
|
503
503
|
raise "Expected res to be '#{count}' for '#{month}' but it was: '#{res}'." if res != count
|
504
504
|
end
|
505
505
|
end
|
506
|
+
|
507
|
+
it "should be able to do various updates from strings" do
|
508
|
+
datet = Datet.new(2012, 06, 17, 10, 50, 30)
|
509
|
+
datet.update_from_str("09:30")
|
510
|
+
|
511
|
+
res = datet.dbstr
|
512
|
+
raise "Expected '2012-06-17 09:30:30' but got: '#{res}'." if res != "2012-06-17 09:30:30"
|
513
|
+
|
514
|
+
datet.update_from_str("4/5")
|
515
|
+
res = datet.dbstr
|
516
|
+
raise "Expected '2012-05-04 09:30:30' but got: '#{res}'." if res != "2012-05-04 09:30:30"
|
517
|
+
|
518
|
+
datet.update_from_str("1/2 2009")
|
519
|
+
res = datet.dbstr
|
520
|
+
raise "Expected '2009-02-01 09:30:30' but got: '#{res}'." if res != "2009-02-01 09:30:30"
|
521
|
+
end
|
506
522
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: datet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.17
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kasper Johansen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-22 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
hash:
|
96
|
+
hash: -2442804437039605202
|
97
97
|
segments:
|
98
98
|
- 0
|
99
99
|
version: "0"
|