• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Date manipulation problem

 
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Dear friends,

When i execute this code with the date mentioned above in LINE 1, the program never terminates and goes into an infinite loop. But if i change the date in line 1 to "01/03/2008". The program works perfectly and gives the difference betwee the two dates in months.

Kindly provide your help.
Regards,
Vijay
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you start in December of 2007, and keep adding months until you reach March of 2007, of course it's not going to stop. You need to ensure that the start date isn't after the end date.

By the way, I think this

should really be
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ulf,

Thanks for the reply.. But even after changing as you said, the program still goes into an infinite loop if the year is 2007 in Line 1 of the above code.


I changed the equalMonthAndYear as static and made a direct call from checkValidFromDate(). But stil the problem exists.

Please guide me if i had misunderstood anything you had given.

Kindly help me.
Regards,
Vijay
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Removing the "new Test()" constructor doesn't help with the problem at hand; that was just something I noticed.

You still need to implement the check for the start being after the end date.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, the problem code is here...



If calc1 doesn't equal calc2, you add a month to calc1 and check again. But what if calc1 is already later than calc2? You can add infinite months to calc1, and it will never equal calc2.

Henry
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic