001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/tool/assessment/business/entity/SortableDate.java $
003: * $Id: SortableDate.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.business.entity;
021:
022: import java.text.SimpleDateFormat;
023: import java.util.Date;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * <p>
030: * Title: Navigo Project: AAM
031: * </p>
032: *
033: * <p>
034: * Description: Standard Date
035: * </p>
036: *
037: * <p>
038: * Purpose: Encapsulate the standard date format used in AAM
039: * </p>
040: *
041: * <p></p>
042: *
043: * <p>
044: * Copyright: Copyright (c) 2003
045: * </p>
046: *
047: * <p>
048: * Company: Stanford University
049: * </p>
050: *
051: * @author Ed Smiley
052: * @version $Id: SortableDate.java 9273 2006-05-10 22:34:28Z daisyf@stanford.edu $
053: */
054: public class SortableDate {
055: private static Log log = LogFactory.getLog(SortableDate.class);
056:
057: /**
058: * standard date format string used in AAM
059: *
060: * @todo would be nice to convert to use properties later on
061: */
062: private static final String SORT_FORMAT = "yyyyMMddkkmm";
063: private Date date;
064:
065: /**
066: * Constructor.
067: *
068: * @param pdate a date object ot be formatted
069: */
070: public SortableDate(Date pdate) {
071: date = pdate;
072: }
073:
074: /**
075: * Overides Object.toString().
076: *
077: * @return the formatted date in yyyMMddkkmm order
078: */
079: public String toString() {
080: try {
081: SimpleDateFormat dateFormatter = new SimpleDateFormat(
082: SORT_FORMAT);
083:
084: return dateFormatter.format(date);
085: } catch (Exception e) {
086: log.debug("Date Exception " + e);
087: }
088:
089: return "unknown date";
090: }
091:
092: /**
093: * Unit test only
094: *
095: * @param args not used
096: */
097: public static void main(String[] args) {
098: Date d = new Date();
099: SortableDate sd = new SortableDate(d);
100: log.debug("debug: " + sd);
101: }
102: }
|