Hi,

I have a few suggestions regarding the following code snippet on the front
page of Joda-Time:

public boolean isAfterPayDay(*DateTime*
<http://joda-time.sourceforge.net/api-release/index.html?org/joda/time/DateTime.html>
datetime) {
  if (datetime.getMonthOfYear() == 2) {   // February is month 2!!
    return datetime.getDayOfMonth() > 26;
  }
  return datetime.getDayOfMonth() > 28;
}

I think it would read better as:

public boolean isAfterPayDay(*DateTime*
<http://joda-time.sourceforge.net/api-release/index.html?org/joda/time/DateTime.html>
datetime) {
  if( datetime.isMonth( DateTimeConstants.FEBRUARY ) ) {
    return datetime.getDayOfMonth() > datetime.getDaysInMonth() - 2;
  }

  return datetime.getDayOfMonth() > datetime.getDaysInMonth() - 2;
}

And even better as:

public boolean isAfterPayDay(*DateTime*
<http://joda-time.sourceforge.net/api-release/index.html?org/joda/time/DateTime.html>
datetime) {
  return datetime.getDayOfMonth() > datetime.getDaysInMonth() - 2;
}

And then you could write:

public boolean isAfterPayDay(*DateTime*
<http://joda-time.sourceforge.net/api-release/index.html?org/joda/time/DateTime.html>
datetime) {
  return datetime.isDayOfMonthAfter( datetime.getDaysInMonth() - 2 );
}

Which implies API changes:

   - boolean DateTime.isYear( int )
   - boolean DateTime.isMonth( int )
   - boolean DateTime.isWeek( int ) (same as isWeekOfYear)
   - boolean DateTime.isDay( int ) (same as isDayOfYear)
   - boolean DateTime.isDayOfYear( int )
   - boolean DateTime.isDayOfMonth( int )
   - boolean DateTime.isDayOfWeek( int )
   - boolean DateTime.isWeekOfYear( int )
   - boolean DateTime.isWeekOfMonth( int )

And:

   - boolean DateTime.isDayOfWeekAfter( int )
   - boolean DateTime.isDayOfMonthAfter( int )
   - boolean DateTime.isDayOfYearAfter( int )
   - boolean DateTime.isDayOfWeekBefore( int )
   - boolean DateTime.isDayOfMonthBefore( int )
   - boolean DateTime.isDayOfYearBefore( int )

And possibly:

   - int DateTime.getDaysInWeek() (superfluous; always seven across all
   calendars?)
   - int DateTime.getDaysInMonth()
   - int DateTime.getDaysInYear()

At the very least, eliminate the magic number 2 in favour of a constant.
This is not only good software development, but it also shows people where
to find (and how to apply) the constants.

Dave
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to