DateUtils.java

  1. package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl;

  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.Locale;

  5. import org.joda.time.DateTime;

  6. /**
  7.  * The Class DateUtils.
  8.  */
  9. public final class DateUtils {

  10.     /** The Constant DATE_FORMAT. */
  11.     private static final String DATE_FORMAT = "dd-MMM-yyyy";

  12.     /**
  13.      * Instantiates a new date utils.
  14.      */
  15.     private DateUtils() {
  16.         // Utility class
  17.     }

  18.     /**
  19.      * Format date.
  20.      *
  21.      * @param date the date
  22.      * @return the string
  23.      */
  24.     public static String formatDate(final Date date) {
  25.         final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
  26.         return simpleDateFormat.format(date);
  27.     }

  28.     /**
  29.      * Strip dates after current date.
  30.      *
  31.      * @param toDate the to date
  32.      * @return the date
  33.      */
  34.     public static Date stripDatesAfterCurrentDate(final Date toDate) {
  35.         final DateTime currentTime = new DateTime();

  36.         if (currentTime.isBefore(toDate.getTime())) {
  37.             return currentTime.plusDays(1).toDate();
  38.         } else {
  39.             return toDate;
  40.         }
  41.     }
  42. }