001    package market;
002    
003    import java.text.SimpleDateFormat;
004    import java.util.Calendar;
005    import java.util.GregorianCalendar;
006    
007    /**
008     * The time format used by the market. This is merely a GregorianCalendar with an overwritten
009     * toString() method.
010     */
011    public class MarketCalendar extends GregorianCalendar {
012    
013        /**
014             * ID for serialization.
015             */
016            private static final long serialVersionUID = -5556068520240140632L;
017    
018            public MarketCalendar() {
019            super();
020        }
021    
022        /**
023         * @param year the new Calendar's year.
024         * @param month the new Calendar's month.
025         * @param date the new Calendar's date.
026         */
027        public MarketCalendar(int year, int month, int date) {
028            super(year, month, date);
029        }
030    
031        /**
032         * Takes an arbitrary Calenar and creates a MarketCalendar from it.
033         * @param gc the original Calendar.
034         * @return a MarketCalendar representing the same date as the passed Calendar.
035         */
036        public static MarketCalendar create(Calendar gc) {
037            return new MarketCalendar(gc.get(YEAR), gc.get(MONTH), gc.get(DATE));
038        }
039    
040        /**
041         * @return the Calendar as dd.MM.yyyy (e.g. 01.01.2000).
042         */
043        public String toString() {
044            SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
045            return sdf.format(getTime());
046        }
047    }