• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: storing NSTimestamp values as GMT, displaying as (client) local?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: storing NSTimestamp values as GMT, displaying as (client) local?


  • Subject: Re: storing NSTimestamp values as GMT, displaying as (client) local?
  • From: Lachlan Deck <email@hidden>
  • Date: Wed, 13 May 2009 08:28:33 +1000

On 13/05/2009, at 7:26 AM, Leif Harrison wrote:

Okay, so I'm finally getting around to implementing this in the app I'm working on, but am having an issue now when I try to switch from using dateformat in my component to using formatter.

Basically, everything displays okay, but when I try to make changes and save them I get this error:

IllegalArgumentException: While trying to invoke the set method "public void com .mobilewarrior .model ._ActivitySchedule .setStartDate(com.webobjects.foundation.NSTimestamp)" on an object of type com.mobilewarrior.model.ActivitySchedule we received an argument of type java.util.Date. This often happens if you forget to use a formatter.

My component looks like the following:
<wo:textfield class="date-time" value="[activitySchedule.startDate]" formatter="[scheduleDateFormatter]" />


And my schedule date formatter looks like this:
public SimpleDateFormat scheduleDateFormatter() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMM d, yyyy hh:mm a");
TimeZone tz = ((Session)session()).timeZone();
dateFormatter.setTimeZone(tz);


log.debug(" format = " + dateFormatter.toPattern());
log.debug(" timezone = " + dateFormatter.getTimeZone().getDisplayName());
return dateFormatter;
}

Yep - so this is quite simply because java's SimpleDateFormat returns a 'java.util.Date'. It knows nothing about NSTimestamps. So what you want to provide in your entity is:


public Object validateStartDate(Object value) {
	if (isManditoryKey(START_DATE_KEY) && value == null) {
		// throw new validation exception with meaningful message
	}
	else if (value instanceof NSTimestamp) {
		return (NSTimestamp)value;
	}
	else if (value instanceof Date) {
		return new NSTimestamp((Date)value);
	}
	return coerced value.toString() to NSTimestamp.
}

Essentially when format values are being set they call validateTakeValueForKey which calls validateKey(object) to coerce the value and/or provide validation.

with regards,
--

Lachlan Deck



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: storing NSTimestamp values as GMT, displaying as (client) local? (From: Leif Harrison <email@hidden>)

  • Prev by Date: Any guesses ?
  • Next by Date: Re: Any guesses ?
  • Previous by thread: Re: storing NSTimestamp values as GMT, displaying as (client) local?
  • Next by thread: Re: storing NSTimestamp values as GMT, displaying as (client) local?
  • Index(es):
    • Date
    • Thread