Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsDate and timezones
https://www.eclipse.org/forums/index.php/mv/msg/396081/936558/#msg_936558
i have a feature label of type EDate which a user can set via a dialog in the properties view. The dialog also contains besides a datepicker and spinners for date and time also a combo box to set the timezone. Therefor a GregorianCalendar is instantiated with the user's selections and a Date object is returned by the method gc.getTime(). My problem is that the timezone setting is ignored, probably because java.util.Date doesn't consider timezones (although there is a deprecated method getTimezoneOffset()).No matter what I'm doing it always shows +0200 as the timezone value. If I deactivate the dialog and modify the timezone value directly in the properties view it works of course, but the user shouldn't take care of the format (yyyy-MM-dd'T'HH:mm:ss'.'SSSZ). Through debugging i found out that the convertion from Date to String is done somewhere in the EMF framework using (Simple)DateFormat. The question is do I have to implement this myself and if so,where and how can this be done?
Regards,
Rami]]>Rami D.2012-10-08T05:26:53-00:00Re: Date and timezones
https://www.eclipse.org/forums/index.php/mv/msg/396081/936645/#msg_936645
Comments below.
On 08/10/2012 7:26 AM, Rami D. wrote:
> Hello,
>
> i have a feature label of type EDate which a user can set via a dialog
> in the properties view. The dialog also contains besides a datepicker
> and spinners for date and time also a combo box to set the timezone.
> Therefor a GregorianCalendar is instantiated with the user's
> selections and a Date object is returned with the method gc.getTime().
> My problem is that the timezone setting is ignored, probably because
> java.util.Date doesn't consider timezones (although there is a
> deprecated method getTimezoneOffset()).
What do you mean by ignored? In the end, a Date is just a long value.
It doesn't record any timezone information...
> No matter what I'm doing it always shows +0200 as the timezone value.
You're expecting it to preserve the timezone? You can see that
GregorianCalendar.getTime() is just a long... This will always be
normalized to be your computer's time zone.
> If I deactivate the dialog and modify the timezone value directly in
> the properties view it works of cause, but the user shouldn't take
> care of the format (yyyy-MM-dd'T'HH:mm:ss'.'SSSZ).
Even here, I expect the timezone is not preserved. It will always be
normalized to your time zone.
> Through debugging i found out that the convertion from Date to String
> is done somewhere in the EMF framework using (Simple)DateFormat. The
> question is do I have to implement this myself and if so,where and how
> can this be done?
I think it's more of a question of expectations. I don't think you can
expect java.util.Date to preserve timezone information. It sounds
like you want something like javax.xml.datatype.XMLGregorianCalendar
which is supported by the DataTime data type in the XMLTypePackage.
>
> Regards,
> Rami]]>Ed Merks2012-10-08T07:24:53-00:00Re: Date and timezones
https://www.eclipse.org/forums/index.php/mv/msg/396081/936719/#msg_936719
thanks for your reply.
"You're expecting it to preserve the timezone? You can see that
GregorianCalendar.getTime() is just a long... This will always be
normalized to be your computer's time zone."
Makes definitely sense and it's exactely what i've realized, but I was confused due to the fact that in the ecore diagram I couldn't find any other data type than EDate for creating time objects.
"It sounds like you want something like javax.xml.datatype.XMLGregorianCalendar"
How can I assign an EAttribute in the ecore diagram to that type? It's not listed as an EType when opening the object selection dialog?
Regards,
Rami
]]>Rami D.2012-10-08T09:05:52-00:00Re: Date and timezones
https://www.eclipse.org/forums/index.php/mv/msg/396081/936812/#msg_936812
didn't use EMF's extended dialog for loading registered packages, so you
have to enter platform:/plugin/org.eclipse.emf.ecore/model/XMLType.ecore
as the URI and then all the data types define there will be available.
On 08/10/2012 11:05 AM, Rami D. wrote:
> Hi Ed,
>
> thanks for your reply.
>
> "You're expecting it to preserve the timezone? You can see that
> GregorianCalendar.getTime() is just a long... This will always be
> normalized to be your computer's time zone."
>
> Makes definitely sense and it's exactely what i've realized, but I was
> confused due to the fact that in the ecore diagram I couldn't find any
> other data type than EDate for creating time objects.
>
>
> "It sounds like you want something like
> javax.xml.datatype.XMLGregorianCalendar"
>
> How can I assign an EAttribute in the ecore diagram to that type? It's
> not listed as an EType when opening the object selection dialog?
>
> Regards,
> Rami
>]]>Ed Merks2012-10-08T11:05:16-00:00Re: Date and timezones
https://www.eclipse.org/forums/index.php/mv/msg/396081/936838/#msg_936838
Regards,
Rami]]>Rami D.2012-10-08T11:39:25-00:00