• 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: Custom Type for NSTimestamp
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom Type for NSTimestamp


  • Subject: Re: Custom Type for NSTimestamp
  • From: David Avendasora <email@hidden>
  • Date: Tue, 9 Dec 2008 09:04:47 -0500

I tried implementing Quinton's solution below, but I'm getting the same error I did with my attempt, which is that everything looks fine when read, date and time are properly parsed and accurate, BUT if I make a change to one of the dates and try to save it, I get the following error:

Save failed: Object 2008-12-05 09:50 Etc/GMT with class java.lang.String is not compatible with com.bestmaid.bakeryManagement.common.utility.MyTimestamp!

There's no stack trace showing up anywhere, just this error.

Which looks to me like takeValueForKey is choking on the conversion of the String to MyTimestamp. The JavaDoc states that takeValueForKey has very limited conversion capabilities.

Dave


On Dec 9, 2008, at 3:57 AM, Q wrote:


On 09/12/2008, at 7:07 AM, David Avendasora wrote:

Hi all,

I'm trying to work with an existing database where they have stored date/time information as a Long Integer in the database.

I'm trying to figure out the best way to use a Custom Type in the Entity Model so the app sees the attributes as NSTimestamps.

I've subclassed NSTimestamp and added a method to convert the db value to it when read, which works, but getting it to write a Long back to the database is what I'm struggling with.

I'm sure it is something simple, but I'm just not seeing it.

Here is how I do something very similar to this:

<pastedGraphic.png>


package net.onthenet.datatypes;

import com.webobjects.foundation.NSTimestamp;

public class UnixTime extends NSTimestamp {

	public UnixTime(NSTimestamp ts) {
		super(ts);
	}

	public UnixTime(long l) {
		super(l * 1000);
	}

	public static UnixTime valueOf(String value) {
		return new UnixTime(Long.valueOf(value).longValue());
	}

	public static UnixTime valueOf(Long value) {
		return new UnixTime(value);
	}

	public String toString() {
		return new Long(getUnixTime()).toString();
	}

	public long getUnixTime() {
		return getTime()/1000;
	}
}


-- Seeya...Q

Quinton Dolan - email@hidden
Gold Coast, QLD, Australia (GMT+10)
Ph: +61 419 729 806




_______________________________________________ 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: 
 >Custom Type for NSTimestamp (From: David Avendasora <email@hidden>)
 >Re: Custom Type for NSTimestamp (From: Q <email@hidden>)

  • Prev by Date: Converting JSON to equivalent Foundation objects
  • Next by Date: [MEETING] WO-NOVA - Next TUESDAY 12/16/08
  • Previous by thread: Re: Custom Type for NSTimestamp
  • Next by thread: Question about UI technique for adding a new object to a list
  • Index(es):
    • Date
    • Thread