jruby-rfc2445 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,16 +3,26 @@ require File.dirname(__FILE__) + '/rfc2445.jar'
3
3
 
4
4
  class ICalParseUtil
5
5
  include_class('com.google.ical.values.IcalParseUtil'){|package,name| "J#{name}" }
6
+ include_class('com.google.ical.values.DateTimeValue')
7
+ include_class('com.google.ical.values.DateValue')
6
8
 
7
9
  # Class Methods
8
10
  class << self
9
11
  def parse_date_value(s, tzid = 'UTC')
10
- timezone = java.util.TimeZone.getTimeZone(tzid || 'UTC')
11
- s ? JIcalParseUtil.parseDateValue(s, timezone) : nil
12
+ timezone = java.util.TimeZone.get_time_zone(tzid || 'UTC')
13
+ s ? JIcalParseUtil.parse_date_value(s, timezone) : nil
12
14
  end
13
15
 
14
16
  def parse_jtime(s, tzid = 'UTC')
15
- s ? JTime.from_date_time_value(parse_date_value(s, tzid || 'UTC')) : nil
17
+ return nil unless s
18
+ value = parse_date_value(s, tzid)
19
+ case value
20
+ when DateTimeValue
21
+ JTime.from_date_time_value(value)
22
+ when DateValue
23
+ timezone = org.joda.time.DateTimeZone.forID(tzid)
24
+ JTime.from_date_value(value, timezone)
25
+ end
16
26
  end
17
27
 
18
28
  # Parse a recurrence block and returns DTSTART, DTEND, RRULE, EXRULE, RDATE, and EXDATE
@@ -43,6 +43,12 @@ class JTime
43
43
  new(datetime)
44
44
  end
45
45
 
46
+ # Initialize a JTime object form DateValue
47
+ def from_date_value(dv, timezone = org.joda.time.DateTimeZone::UTC)
48
+ datetime = JDateTime.new(dv.year, numeric_month(dv.month), dv.day, 0, 0, 0, 0, timezone)
49
+ new(datetime)
50
+ end
51
+
46
52
  # Initialize a JTime object from DateTimeValue
47
53
  def from_date_time_value(dtv)
48
54
  utc(dtv.year, dtv.month, dtv.day, dtv.hour, dtv.minute, dtv.second)
@@ -426,6 +426,12 @@ describe ICalParseUtil do
426
426
  jtime3 = ICalParseUtil.parse_datetime(nil)
427
427
  jtime3.should be_nil
428
428
  end
429
+
430
+ it "should parse date into JTime" do
431
+ jtime = ICalParseUtil.parse_datetime('DTSTART;VALUE=DATE:20100129')
432
+ jtime.should be_instance_of(JTime)
433
+ jtime.hour.should == 0
434
+ end
429
435
  end
430
436
 
431
437
  describe RecurrenceTime do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jruby-rfc2445
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Luk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-24 00:00:00 -07:00
12
+ date: 2010-01-29 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15