Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Zulu time when timezones specified #20

Closed
nicky-isaacs opened this issue Jan 28, 2016 · 3 comments
Closed

Disable Zulu time when timezones specified #20

nicky-isaacs opened this issue Jan 28, 2016 · 3 comments

Comments

@nicky-isaacs
Copy link

I have multiple VTIMEZONE objects specified in my calendar, all of which are being used by VEVENTS. I do not want to specify a timezone for the calendar as a whole, but rather on individual events.

Perhaps I am mistaken, but it seems as though specifying a timezone property on a VEvent object should cause it to be serialized without a Zulu time. An example, using Scala but should work same in Java:

val timezoneIds = List("America/Seattle")

// Create some timezones
val timezones: List[VTimezone] = buildTimezones(timezoneIds)

// Create a DateStart
val dtStart = new DateStart(startTime)
val dtEnd = new DateEnd(endTime)

// Create timezone params and add to start and end
val params = new ICalParameters()
params.setTimezoneId(timezoneIds(0)) // Example, use the first timezone
dtStart.setParameters(params)
dtEnd.setParameters(params)

// Add the start and end to an event
val event = new VEvent()
event.setProperty(dtStart)
event.setProperty(dtEnd)

val calendar = new iCalendar()

calendar.addEvent(event)


val writer = new ICalWriter(buffer, ICalVersion.V2_0)

// Add the timezone
writer.getTimezoneInfo.assign(timezones(0), TimeZone.getTimeZone(timezoneIds(0))

// Write to a string
val buffer = new ByteArrayOutputStream()
val written = f(writer)
written.flush()
written.close()
val calString = new String(buffer.toByteArray)

// calStrig now contains a VTimezone object, and VEvent object in the format
// DTSTART;TZID=America/Seattle:20160505T150000Z

There is mention in the "Working with Timezones" page about using icalWriter.getTimezoneInfo().setDefaultTimeZone(tz); to set timezones for the calendar as a whole. I do not need to specify a global timezone as all events have a timezone specified, however if that is the best solution I could specify a bunk timezone to prevent the Zulu time specification.

Hope this makes sense, happy to provide more clarification

@mangstadt
Copy link
Owner

Nick,

Adding a timezone ID parameter to a property will NOT cause it to be formatted in that timezone. To format a property in a specific timezone, you have to use the writer's TimezoneInfo object.

ICalendar ical = new ICalendar();
VEvent event = new VEvent();
DateStart dtstart = ...
event.setProperty(dtstart);
DateEnd dtend = ...
event.setProperty(dtend);
ical.addEvent(event);

ICalWriter writer = ...
VTimezone vtimezone = ...
TimeZone timezone = TimeZone.getTimeZone(...);
writer.getTimezoneInfo.assign(vtimezone, timezone);
writer.getTimezoneInfo().setTimeZone(dtstart, timezone);
writer.getTimezoneInfo().setTimeZone(dtend, timezone);
writer.write(ical);

As it stands now, there's no way to assign a timezone to an event as a whole. You have to individually assign each of the event's date/time properties to the timezone. But maybe I will add this feature. Thanks for the idea!

@nicky-isaacs
Copy link
Author

Mike,

Ah! thanks for the info. Will try that. Will look into a PR to support this

Cheers,

Nick

@mangstadt
Copy link
Owner

Closing. See #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants