package com.kiasoft.util; /* ------------------------------------------------------------------ * Kiasoft, Inc. * http://kiasoft.com * * Copyright (c) 2004-2006 Kiasoft, Inc. * ------------------------------------------------------------------ */ /* * date presentations in nice format */ import java.util.*; import java.text.*; public class LocalDate { private static Date showDate = new Date(); private static Locale usLocale = new Locale("en", "US"); private static String pattern = "EEE, MMM d, yyyy K:mm a"; private static String REPORTpattern = "MM/dd/yyyy"; // default compat with mysql date format private static String SQLpattern = "yyyy-MM-dd H:mm:ss"; private static String SQLpatternNoTime = "yyyy-MM-dd"; /* * displays long date formate */ static public String display() { SimpleDateFormat formatter; formatter = new SimpleDateFormat(pattern, usLocale); return formatter.format(showDate); } /* * set time to be now */ public void setNow() { this.showDate = new Date(); return; } /* * default set date method */ public void setDate() { try { Date oldDate = DateFormat.getDateInstance( DateFormat.SHORT ).parse( "01/01/2000" ); this.showDate = oldDate; return; } catch ( Exception e ) { // parse exception return; } } /* * force set date with a date object */ public void setDate(Date v) { try { // initial old date of Jan 1, 2000 -> default date Date oldDate = DateFormat.getDateInstance( DateFormat.SHORT ).parse( "01/01/2000" ); if ( v != null ) { this.showDate = v; long diff = oldDate.getTime() - v.getTime(); if ( diff > 0 ) { this.showDate = oldDate; } } else { this.showDate = oldDate; } return; } catch ( Exception e ) { // problem.. } } /* * show us a report date MM/DD/YYYY type */ public String reportDate() { SimpleDateFormat formatter; formatter = new SimpleDateFormat(REPORTpattern, usLocale); String dte = formatter.format(showDate); if ( dte.equals("01/01/2000") ) { dte = ""; } return dte; } /* * get a sql compatible date string */ public String sqlDate() { SimpleDateFormat formatter; formatter = new SimpleDateFormat(SQLpattern, usLocale); return formatter.format(showDate); } /* * get a sql compatible date string with no time data */ public String sqlDateNoTime() { SimpleDateFormat formatter; formatter = new SimpleDateFormat(SQLpatternNoTime, usLocale); return formatter.format(showDate); } }