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

XProperty as Duration #26

Closed
gbero opened this issue Jan 19, 2015 · 2 comments
Closed

XProperty as Duration #26

gbero opened this issue Jan 19, 2015 · 2 comments

Comments

@gbero
Copy link

gbero commented Jan 19, 2015

Hi,

I'd like to parse a duration field i.e : "PT30M" stored in a XProperty but :

java.lang.ClassCastException: net.fortuna.ical4j.model.property.XProperty cannot be cast to net.fortuna.ical4j.model.property.Duration

which makes sense because they both extends from Property...

@benfortuna
Copy link
Member

The solution is to write your own custom property class and inject it into the service loader via META-INF/services/net.fortuna.ical4j.model.PropertyFactory. For example:

https://github.com/ical4j/ical4j-extensions/blob/master/src/main/resources/META-INF/services/net.fortuna.ical4j.model.PropertyFactory

For your property implementation you could start by copying (or extending) the Duration class, and essentially just define a new factory implementation.

If the property is a "standard" custom property you could also consider forking the ical4j-extensions repository and create a pull request back to the main repo.

regards,
ben

@gbero
Copy link
Author

gbero commented Jan 22, 2015

Thanks for your answer!

@gbero gbero closed this as completed Jan 22, 2015
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