Re: [appengine-java] how to store java "Date" type in specific timezone?

2012-01-25 Thread Jeff Schnitzer
I store DateTime, LocalDate, LocalDateTime, and DateTimeZone quite a
lot, but I use Objectify (disclosure: I'm the lead author) which
handles the translation for you (if you enable it).  ReadableInstant
objects (eg DateTime) are stored natively as java.util.Date and Local
objects (LocalDate, LocalDateTime, etc) are stored as the ISO-8601
string.

Jeff

On Wed, Jan 25, 2012 at 4:44 PM, Kesava Neeli  wrote:
> Thanks Jeff. I used JodaTime before but I was stuck with java.util.Date
> since appengine allows only standard java data types. I don't think Joda
> Time object will work on appeninge. Will give a try. Have you stored
> JodaTime objects in datastore?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine-java/-/vHFYiyYJGTkJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] how to store java "Date" type in specific timezone?

2012-01-25 Thread Kesava Neeli
Thanks Jeff. I used JodaTime before but I was stuck with java.util.Date 
since appengine allows only standard java data types. I don't think Joda 
Time object will work on appeninge. Will give a try. Have you stored 
JodaTime objects in datastore? 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/vHFYiyYJGTkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] how to store java "Date" type in specific timezone?

2012-01-25 Thread Jeff Schnitzer
Taking a step back, I should say that if you're using java.util.Date
with timezone info, "you're doing it wrong".  java.util.Date is a
trainwreck, and any methods that affect an internal notion of a TZ
have been deprecated.  If you care about timezones, using Date is a
mistake - it's best to think of Date as purely a wrapper for
millis-since-epoch, nothing more.

I strongly recommend purging java.util.Date from your code and using
Joda Time instead.  You can use DateTime to represent an instant (and
set TZ if you want to format it for a locale) or you can use
LocalDateTime to store an abstract notion of a time without a TZ -
which, if you're taking a date as user input, is often what you really
want to persist.

Jeff

On Wed, Jan 25, 2012 at 2:17 PM, Matthew Jaggard  wrote:
> You could create a sortable date format string. For example, convert the
> date to GMT and store it -mm-dd hh:mm:ss.nnn then store the timezone
> afterwards so you can convert back to the date/time in the timezone.
>
> On 25 Jan 2012 19:05, "Kesava Neeli"  wrote:
>>
>> Thanks. That's what I was doing for some date fields now. Store the date
>> in a well formatted string and then do conversions. But it becomes tough
>> when you want to build a query "get me all records in last day" and the
>> datastore for that object contains thousands of  records. With the strings,
>> you need to iterate through all records, get a date and then do a
>> comparison.
>>
>> With "date" data type, you can rely on appengine to return correct data.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine for Java" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/google-appengine-java/-/7sg4mVI55SMJ.
>> To post to this group, send email to
>> [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] how to store java "Date" type in specific timezone?

2012-01-25 Thread Matthew Jaggard
You could create a sortable date format string. For example, convert the
date to GMT and store it -mm-dd hh:mm:ss.nnn then store the timezone
afterwards so you can convert back to the date/time in the timezone.
On 25 Jan 2012 19:05, "Kesava Neeli"  wrote:

> Thanks. That's what I was doing for some date fields now. Store the date
> in a well formatted string and then do conversions. But it becomes tough
> when you want to build a query "get me all records in last day" and the
> datastore for that object contains thousands of  records. With the strings,
> you need to iterate through all records, get a date and then do a
> comparison.
>
> With "date" data type, you can rely on appengine to return correct data.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine-java/-/7sg4mVI55SMJ.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] how to store java "Date" type in specific timezone?

2012-01-25 Thread Kesava Neeli
Thanks. That's what I was doing for some date fields now. Store the date in 
a well formatted string and then do conversions. But it becomes tough when 
you want to build a query "get me all records in last day" and the 
datastore for that object contains thousands of  records. With the strings, 
you need to iterate through all records, get a date and then do a 
comparison. 

With "date" data type, you can rely on appengine to return correct data. 

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/7sg4mVI55SMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



Re: [appengine-java] how to store java "Date" type in specific timezone?

2012-01-25 Thread Jeff Schnitzer
You must store the TZ as a separate field.

Alternatively, if you don't need the date to be indexed, you can
convert it back and forth to a String that preserves TZ info (eg, the
ISO-8601 format).

Jeff

On Wed, Jan 25, 2012 at 12:53 PM, Kesava Neeli  wrote:
> Hi,
>
> I have a java.util.Date data type in my object.
>
> Date now = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"),
> Locale.US).getTime();
>
> When I persist the object and look at the entity, I see the type stored as
> "gd:when" as the kind of element.
>
> I see the value as 2012-01-25 01:01:37.938000 which is UTC time.
>
> How can I save the time in my desired timezone? The java Date type has no
> timezone setting explicitly and appengine only allows java.util.Date as a
> valid date type from java.
>
> Thanks
> Neeli
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-appengine-java/-/__Q5MEGh6jwJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.