You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Simon Steinacker <si...@student.uibk.ac.at> on 2007/11/05 21:56:51 UTC

axis Calendar time zones

Hello,

I am currently using axis 1.3, working with java Calendar objects across 
Web Services.
I realized, that axis by default sets the timezone to GMT when 
serializing dates.

How can I tell axis which timezone it should use?
Thanks a lot,
Simon

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: axis Calendar time zones

Posted by Alex Dickinson <al...@redback.com>.
I wish I could have assumed that all dates were in UTC time. The
back-end API I am dealing requires me to set a timezone depending on
other values in the request.

I will keep that in mind for the next time.

Cheers,
Alex

Anthony Bull wrote:
> Why don't you just set the default timezone for your web service in the
> skeleton init() method?
> 
> Assuming all dates come through in UTC time in the XML messages, they
> will be converted correctly without having to do any mucking around.
> 
> Alex Dickinson wrote:
>> Actually... that date format doesn't work either. Java timezones are not
>> compatible with ISO8601 formats.
>>
>> The is what I ended up doing (and it is uggggly):
>>
>> private final static String[] ISO_8601_DATE_FORMATS =
>>       new String[]
>>           {
>>               "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
>>               "yyyy-MM-dd'T'HH:mm:ss.SSS",
>>               "yyyy-MM-dd'T'HH:mm:ssZ",
>>               "yyyy-MM-dd'T'HH:mm:ss",
>>               "yyyy-MM-dd",
>>           };
>>
>>
>> String str = "2007-05-10T15:22:07.000Z"; // the time to translate
>> TimeZone tz = null; // fill this in with the time zone that
>>                     //non-timezone  encoded times will use.
>>
>> Date result = null;
>>
>> // convert timezones from ISO 8601 notation
>> str = str.replaceAll("Z$", "+0000");
>> str = str.replaceAll("([\\+\\-]\\d\\d):(\\d\\d)$", "$1$2");
>>
>> for (String format : ISO_8601_DATE_FORMATS)
>> {
>>   try
>>   {
>>     SimpleDateFormat dateFormat = new SimpleDateFormat(format);
>>
>>     // add in the timezone if the format specifies it.
>>     if (! format.endsWith("Z"))
>>     {
>>       dateFormat.setTimeZone(tz);
>>     }
>>     result = dateFormat.parse(str);
>>
>>     break;
>>   }
>>   catch (ParseException ex)
>>   {
>>     // do nothing
>>   }
>> }
>>
>> if (result == null)
>> {
>>   throw new ParseException();
>> }
>>
>>
>> Cheers,
>> -aLEX
>>
>>
>>
>>
>> Walker, Jeff wrote:
>>   
>>> I think we all agreed many posts ago that it is best (if not elementary)
>>> to transfer dates via plain strings, defined in schema. It definitely
>>> doesn't cause you any integration issues since you take the date and
>>> simply build the appropriate object from it. (Surprisingly ugly, for
>>> Java).
>>>
>>> // Take a string and create a Calendar object from it
>>> Date requiredDate = null;
>>> String existingString = "2007-05-10T15:22:07.000Z"; // Get this from web
>>> service
>>> SimpleDateFormat sdf = new
>>> SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
>>> try {
>>> 	requiredDate = sdf.parse(formattedStr);
>>> }
>>> catch (java.text.ParseException pe) {
>>> 	System.out.println("We got a parsing exception: " +
>>> pe.getMessage()); 
>>> }
>>> Calendar newCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
>>> newCal.setTime(requiredDate);
>>>
>>> You might need to pass the timezone as a separate string field, I think.
>>> Here I used "GMT" but you will pass it as a separate parameter in a web
>>> service call.
>>>
>>>
>>> Also, looking at Axis 1.3 src it builds a SimpleDateFornmat object from
>>> the GMT timezone. There is no way to change that unless you edit the
>>> org.apache.axis.encoding.ser.CalendarSerializer class and then recompile
>>> Axis. Yuk.
>>> -jeff
>>>
>>>  
>>>
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: Ford, Jennifer M. [mailto:JENNFORD@SOUTHERNCO.COM] 
>>> Sent: Monday, November 05, 2007 4:05 PM
>>> To: axis-user@ws.apache.org
>>> Subject: RE: axis Calendar time zones
>>>
>>> Unfortunately, I don't think that's possible.  You'll just have to
>>> translate to/from GMT on each end.
>>>
>>> -----Original Message-----
>>> From: Simon Steinacker [mailto:simon.steinacker@student.uibk.ac.at] 
>>> Sent: Monday, November 05, 2007 2:57 PM
>>> To: axis-user@ws.apache.org; axis-dev@ws.apache.org
>>> Subject: axis Calendar time zones
>>>
>>> Hello,
>>>
>>> I am currently using axis 1.3, working with java Calendar objects across
>>> Web Services.
>>> I realized, that axis by default sets the timezone to GMT when
>>> serializing dates.
>>>
>>> How can I tell axis which timezone it should use?
>>> Thanks a lot,
>>> Simon
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>
>>>
>>>
>>>     
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>>
>>
>>   
> 
> 
> -- 
> 
> Anthony
> ------------------------------------- 
> Anthony Bull
> Senior Developer
> Black Coffee Software Ltd
> PO Box 10-192 The Terrace
> Wellington, New Zealand
>  
> anthony.bull@bcsoft.co.nz
> Ph  +64 4 472 8818
> Fax +64 4 472 8811
> ------------------------------------- 
> www.bcsoft.co.nz
> --------------------------------------------------------------- 
> This email may contain confidential or privileged information, 
> and is intended for use only by the addressee, or addressees. 
> If you are not the intended recipient please advise the sender 
> immediately and do not copy, use or disclose the contents to 
> any other person or organisation.
> Black Coffee Software Ltd accepts no responsibility for viruses 
> received with this email, or to any changes made to the original 
> content. Any views or opinions expressed in this email may be
> personal to the sender and are not necessarily those of Black 
> Coffee Software Ltd.
> --------------------------------------------------------------- 
> 
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org For additional
> commands, e-mail: axis-user-help@ws.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: axis Calendar time zones

Posted by Alex Dickinson <al...@redback.com>.
Actually... that date format doesn't work either. Java timezones are not
compatible with ISO8601 formats.

The is what I ended up doing (and it is uggggly):

private final static String[] ISO_8601_DATE_FORMATS =
      new String[]
          {
              "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
              "yyyy-MM-dd'T'HH:mm:ss.SSS",
              "yyyy-MM-dd'T'HH:mm:ssZ",
              "yyyy-MM-dd'T'HH:mm:ss",
              "yyyy-MM-dd",
          };


String str = "2007-05-10T15:22:07.000Z"; // the time to translate
TimeZone tz = null; // fill this in with the time zone that
                    //non-timezone  encoded times will use.

Date result = null;

// convert timezones from ISO 8601 notation
str = str.replaceAll("Z$", "+0000");
str = str.replaceAll("([\\+\\-]\\d\\d):(\\d\\d)$", "$1$2");

for (String format : ISO_8601_DATE_FORMATS)
{
  try
  {
    SimpleDateFormat dateFormat = new SimpleDateFormat(format);

    // add in the timezone if the format specifies it.
    if (! format.endsWith("Z"))
    {
      dateFormat.setTimeZone(tz);
    }
    result = dateFormat.parse(str);

    break;
  }
  catch (ParseException ex)
  {
    // do nothing
  }
}

if (result == null)
{
  throw new ParseException();
}


Cheers,
-aLEX




Walker, Jeff wrote:
> I think we all agreed many posts ago that it is best (if not elementary)
> to transfer dates via plain strings, defined in schema. It definitely
> doesn't cause you any integration issues since you take the date and
> simply build the appropriate object from it. (Surprisingly ugly, for
> Java).
> 
> // Take a string and create a Calendar object from it
> Date requiredDate = null;
> String existingString = "2007-05-10T15:22:07.000Z"; // Get this from web
> service
> SimpleDateFormat sdf = new
> SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
> try {
> 	requiredDate = sdf.parse(formattedStr);
> }
> catch (java.text.ParseException pe) {
> 	System.out.println("We got a parsing exception: " +
> pe.getMessage()); 
> }
> Calendar newCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
> newCal.setTime(requiredDate);
> 
> You might need to pass the timezone as a separate string field, I think.
> Here I used "GMT" but you will pass it as a separate parameter in a web
> service call.
> 
> 
> Also, looking at Axis 1.3 src it builds a SimpleDateFornmat object from
> the GMT timezone. There is no way to change that unless you edit the
> org.apache.axis.encoding.ser.CalendarSerializer class and then recompile
> Axis. Yuk.
> -jeff
> 
>  
> 
> 
> 
> 
> 
> -----Original Message-----
> From: Ford, Jennifer M. [mailto:JENNFORD@SOUTHERNCO.COM] 
> Sent: Monday, November 05, 2007 4:05 PM
> To: axis-user@ws.apache.org
> Subject: RE: axis Calendar time zones
> 
> Unfortunately, I don't think that's possible.  You'll just have to
> translate to/from GMT on each end.
> 
> -----Original Message-----
> From: Simon Steinacker [mailto:simon.steinacker@student.uibk.ac.at] 
> Sent: Monday, November 05, 2007 2:57 PM
> To: axis-user@ws.apache.org; axis-dev@ws.apache.org
> Subject: axis Calendar time zones
> 
> Hello,
> 
> I am currently using axis 1.3, working with java Calendar objects across
> Web Services.
> I realized, that axis by default sets the timezone to GMT when
> serializing dates.
> 
> How can I tell axis which timezone it should use?
> Thanks a lot,
> Simon
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: axis Calendar time zones

Posted by "Walker, Jeff" <Je...@fmr.com>.
I think we all agreed many posts ago that it is best (if not elementary)
to transfer dates via plain strings, defined in schema. It definitely
doesn't cause you any integration issues since you take the date and
simply build the appropriate object from it. (Surprisingly ugly, for
Java).

// Take a string and create a Calendar object from it
Date requiredDate = null;
String existingString = "2007-05-10T15:22:07.000Z"; // Get this from web
service
SimpleDateFormat sdf = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
try {
	requiredDate = sdf.parse(formattedStr);
}
catch (java.text.ParseException pe) {
	System.out.println("We got a parsing exception: " +
pe.getMessage()); 
}
Calendar newCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
newCal.setTime(requiredDate);

You might need to pass the timezone as a separate string field, I think.
Here I used "GMT" but you will pass it as a separate parameter in a web
service call.


Also, looking at Axis 1.3 src it builds a SimpleDateFornmat object from
the GMT timezone. There is no way to change that unless you edit the
org.apache.axis.encoding.ser.CalendarSerializer class and then recompile
Axis. Yuk.
-jeff

 





-----Original Message-----
From: Ford, Jennifer M. [mailto:JENNFORD@SOUTHERNCO.COM] 
Sent: Monday, November 05, 2007 4:05 PM
To: axis-user@ws.apache.org
Subject: RE: axis Calendar time zones

Unfortunately, I don't think that's possible.  You'll just have to
translate to/from GMT on each end.

-----Original Message-----
From: Simon Steinacker [mailto:simon.steinacker@student.uibk.ac.at] 
Sent: Monday, November 05, 2007 2:57 PM
To: axis-user@ws.apache.org; axis-dev@ws.apache.org
Subject: axis Calendar time zones

Hello,

I am currently using axis 1.3, working with java Calendar objects across
Web Services.
I realized, that axis by default sets the timezone to GMT when
serializing dates.

How can I tell axis which timezone it should use?
Thanks a lot,
Simon

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: axis Calendar time zones

Posted by so...@lidp.com.
Simon,

Does it not serialize qualifiers such as Z-1, Z+1, Z+2, etc. for one hr before
zulu (UT), 1 hr behind zulu, 2 hrs behind zulu, respectively?

Tom

On Mon, Nov 05, 2007 at 03:04:59PM -0600, Ford, Jennifer M. wrote:
> Unfortunately, I don't think that's possible.  You'll just have to
> translate to/from GMT on each end.
> 
> -----Original Message-----
> From: Simon Steinacker [mailto:simon.steinacker@student.uibk.ac.at] 
> Sent: Monday, November 05, 2007 2:57 PM
> To: axis-user@ws.apache.org; axis-dev@ws.apache.org
> Subject: axis Calendar time zones
> 
> Hello,
> 
> I am currently using axis 1.3, working with java Calendar objects across
> Web Services.
> I realized, that axis by default sets the timezone to GMT when
> serializing dates.
> 
> How can I tell axis which timezone it should use?
> Thanks a lot,
> Simon
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: axis Calendar time zones

Posted by "Ford, Jennifer M." <JE...@SOUTHERNCO.COM>.
Unfortunately, I don't think that's possible.  You'll just have to
translate to/from GMT on each end.

-----Original Message-----
From: Simon Steinacker [mailto:simon.steinacker@student.uibk.ac.at] 
Sent: Monday, November 05, 2007 2:57 PM
To: axis-user@ws.apache.org; axis-dev@ws.apache.org
Subject: axis Calendar time zones

Hello,

I am currently using axis 1.3, working with java Calendar objects across
Web Services.
I realized, that axis by default sets the timezone to GMT when
serializing dates.

How can I tell axis which timezone it should use?
Thanks a lot,
Simon

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org