|
On 29/03/2006, at 12:26 PM, praveen gunda wrote:
my simple question is: 1 + 1 + 1 => 3 <= 2 + 1 but Date + %months(2) is not equal to Date + %months(1) + %months(1) Here date need not always be the end of month.
Actually it does have to be the end (or at least the last few days) otherwise you won't see this so-called problem.
Eg: 2006-01-30 is not End Of Month 2006-01-30 + %months(2) = 2006-03-31
Not in RPG IV. 2006-01-30 + %months(2) = 2006-03-30
but 2006-01-30 + %months(1) + %months(1) is not equal to 2006-03-31
In RPG IV the answer is 2006-03-28 due to intermediate results: 2006-01-30 plus 01 = 2006-02-28 plus 01 = 2006-03-28Don't know why you're complaining. It's documented behaviour. You said previously that you "never had this problem with Java" but I can prove that Java behaves "inconsistently" too.
import java.util.*; public class PraveenCalendar2 { public static void main(String[] args) { GregorianCalendar gc1 = new GregorianCalendar(2006, 0, 30); GregorianCalendar gc2 = new GregorianCalendar(2006, 0, 30); System.out.println(gc1.getTime()); gc1.add(Calendar.MONTH, 1); System.out.println(gc1.getTime()); gc1.add(Calendar.MONTH, 1); System.out.println(gc1.getTime()); System.out.println(""); System.out.println(gc2.getTime()); gc2.add(Calendar.MONTH, 2); System.out.println(gc2.getTime());} }
> java PraveenCalendar2 Mon Jan 30 00:00:00 GMT 2006 Tue Feb 28 00:00:00 GMT 2006 Tue Mar 28 00:00:00 GMT 2006 Mon Jan 30 00:00:00 GMT 2006 Thu Mar 30 00:00:00 GMT 2006 You can see that: Date + month(1) + month(1) <> Date + month(2)However both RPG IV and Java provide the same dates for the same calculation.:
Date = 2006-01-30 Date + month(1) + month(1) = 2006-03-28 Date + month(2) = 2006-03-30Consistent results is what is important even if they don't fit your view of "correct".
I don't know why I'm bothering with this topic anyway ... it's inane. Date maths is not arithmetic--it has it's own set of rules, nor is it reciprocal:
2006-01-31 + %month(1) - %month(1) <> 2006-01-31 Accept the behaviour and move on. Regards, Simon Coulter. -------------------------------------------------------------------- FlyByNight Software AS/400 Technical Specialists http://www.flybynight.com.au/ Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 /"\ Fax: +61 3 9419 0175 \ / X ASCII Ribbon campaign against HTML E-Mail / \ --------------------------------------------------------------------
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.