• 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 formatter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: custom formatter


  • Subject: Re: custom formatter
  • From: Dev WO <email@hidden>
  • Date: Mon, 18 Jul 2005 22:21:59 +0200

Thanks Jerry,
you are right, it's pretty much more a numerical stuff than a date manipulation.
Thanks to Anfy who helped me clear that, I did a method (not very optimized for now) that will get the warranty to a combination of year,month,week which will do the trick for now.
Thanks for you input, I'll mark it to make sure I won't forget when I'll get back to optimize this method.


Xavier



If you've stored the warranty information as an integer number of weeks in your database, and you're willing to accept 1 month = 4 weeks (exactly), then you've got a simple numeric problem rather than a date problem.

I would approach it in something like the following way:

public String warrantyUnit(int warrantyWeeks) {
    if ((warrantyWeeks / 52) * 52 == warrantyWeeks) {
         return "years";
    if ((warrantyWeeks / 4) * 4 == warrantyWeeks) {
         return "months";
    return weeks;
}

public int warrantyTime(int warrantyWeeks, String warrantyUnit) {
    if ("years".isEqual(warrantyUnit))
        return (warrantyWeeks / 52);
    if ("months".isEqual(warrantyUnit))
        return (warrantyWeeks / 4);
    return warrantyWeeks;
}

Under Objective C, I would have defined warranty as a structure:

struct warranty {
    String unit;
    int period;
}

and done the whole job in a single method that returned said structure, but we're no longer in that environment and making warranty a Java class seemed a little heavy handed.

Regards,
Jerry


On Jul 18, 2005, at 7:20 AM, Dev WO wrote:


Hi,
I'm not sure the subject is correct, but here's my problem:
I've got warranty validity information stored as weeks in the database. I'd like to display them in either week(s), month or year (s), but not like "3.5 month", I'd like the number to always be an integer (not rounded), so a 6 weeks warranty will be displayed "6 weeks" and a 4 weeks warranty will be dispayed "1 month".


Does anyone has a suggestion for this? I tried to dig into different date APIs (like the apache common and the java one), but I don't think it's the way to go...

Thanks

Xavier
_______________________________________________
WebObjects-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/webobjects-dev




--
__ Jerry W. Walker, Partner
C o d e F a b, LLC - "High Performance Industrial Strength Internet Enabled Systems"
email@hidden
212 465 8484 X-102 office
212 465 9178 fax






_______________________________________________ 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 formatter (From: Dev WO <email@hidden>)
 >Re: custom formatter (From: "Jerry W. Walker" <email@hidden>)

  • Prev by Date: Re: WO 5.3 Licensing
  • Next by Date: EOModeler & OpenBase 9
  • Previous by thread: Re: custom formatter
  • Next by thread: Re: custom formatter
  • Index(es):
    • Date
    • Thread