/********************************************************************************** * $URL: https://source.sakaiproject.org/svn/kernel/trunk/kernel-impl/src/test/java/org/sakaiproject/content/impl/serialize/impl/test/MockTime.java $ * $Id: MockTime.java 105077 2012-02-24 22:54:29Z ottenhoff@longsight.com $ *********************************************************************************** * * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Sakai Foundation * * Licensed under the Educational Community License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.opensource.org/licenses/ECL-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * **********************************************************************************/ package org.sakaiproject.content.impl.serialize.impl.test; import java.text.DateFormat; import java.text.ParseException; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import org.sakaiproject.time.api.Time; import org.sakaiproject.time.api.TimeBreakdown; /** * <p> * MyTime is an implementation of the Time API Time. * </p> */ public class MockTime implements Time { /** A fixed class serian number. */ private static final long serialVersionUID = 1L; /** The milliseconds since... same as Date */ protected long m_millisecondsSince = 0; /** * construct from a string, in our format, GMT values * * @param str * time format string * @throws ParseException */ public MockTime(String str) { // use formatter A: yyyyMMddHHmmssSSS DateFormat fmt = (DateFormat)(new SimpleDateFormat("yyyyMMddHHmmssSSS")); TimeZone tz = TimeZone.getTimeZone("GMT"); fmt.setTimeZone(tz); ParsePosition pos = new ParsePosition(0); Date date = fmt.parse(str,pos); m_millisecondsSince = date.getTime(); } /** * construct as now */ public MockTime() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * construct from a Long * * @param l * time value in ms since... */ public MockTime(long l) { m_millisecondsSince = l; } /** * construct from individual ints, and the zone. * * @param zone * The time zone. * @param year * full year (i.e. 1999, 2000) * @param month * month in year (1..12) * @param day * day in month (1..31) * @param hour * hour in day (0..23) * @param minuet * minute in hour (0..59) * @param second * second in minute (0..59) * @param millisecond * millisecond in second (0..999) */ public MockTime(TimeZone zone, int year, int month, int day, int hour, int minute, int second, int millisecond) { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * construct from time breakdown, and the zone. * * @param zone * The time zone. * @param tb * The TimeBreakdown with the values. */ public MockTime(TimeZone zone, TimeBreakdown tb) { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public Object clone() { return new MockTime(m_millisecondsSince); } /** * {@inheritDoc} */ public String toString() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringSql() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocal() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringGmtFull() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalFull() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalFullZ() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringGmtShort() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalShort() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringGmtTime() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalTime() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalTimeZ() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalTime24() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringGmtDate() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalDate() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringLocalShortDate() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } public static final SimpleDateFormat RFC822DATEFORMAT // = new SimpleDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Locale.US); = new SimpleDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z"); /** * {@inheritDoc} */ public String toStringRFC822Local() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String toStringFilePath() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public boolean equals(Object obj) { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public int hashCode() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public int compareTo(Object o) { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public void setTime(long l) { m_millisecondsSince = l; } /** * {@inheritDoc} */ public long getTime() { return m_millisecondsSince; } /** * {@inheritDoc} */ public boolean before(Time other) { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public boolean after(Time other) { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public TimeBreakdown breakdownGmt() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public TimeBreakdown breakdownLocal() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } /** * {@inheritDoc} */ public String getDisplay() { throw new UnsupportedOperationException("This class is only to be used for conversion purposes"); } }