Skip to content

Commit

Permalink
Added convenience constructor for timezone initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Sep 19, 2019
1 parent 72df796 commit c197c0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/net/fortuna/ical4j/model/DateTime.java
Expand Up @@ -272,6 +272,11 @@ public DateTime(final java.util.Date date) {
}
}

public DateTime(final java.util.Date date, TimeZone timeZone) {
this(date);
setTimeZone(timeZone);
}

/**
* Constructs a new DateTime instance from parsing the specified string
* representation in the default (local) timezone.
Expand Down
12 changes: 12 additions & 0 deletions src/test/groovy/net/fortuna/ical4j/model/DateTimeSpec.groovy
Expand Up @@ -184,4 +184,16 @@ class DateTimeSpec extends Specification {
cleanup:
TimeZone.default = originalTimezone
}

def 'datetime constructor using calendar'() {
given: 'a calendar instance'
def cal = java.util.Calendar.instance
cal.timeZone = java.util.TimeZone.getTimeZone('Europe/Berlin')

when: 'a datetime is created'
DateTime dateTime = [cal.time, tzRegistry.getTimeZone(cal.timeZone.getID())]

then: 'it has the timezone set'
dateTime.timeZone == tzRegistry.getTimeZone(cal.timeZone.getID())
}
}

0 comments on commit c197c0a

Please sign in to comment.