Derek Hulley ff07ea1e7d Merged 1.4 to HEAD
svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4192 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4197 .
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4205 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4206 .
   svn resolved root\projects\repository\source\java\org\alfresco\filesys\server\config\ServerConfiguration.java
   svn revert root\projects\repository\config\alfresco\version.properties
   svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4219 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4224 .


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4631 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2006-12-18 11:58:55 +00:00

136 lines
3.6 KiB
Java

/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* 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.alfresco.filesys.ftp;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* FTP Date Utility Class
*
* @author GKSpencer
*/
public class FTPDate
{
// Constants
//
// Six months in ticks
protected final static long SIX_MONTHS = 183L * 24L * 60L * 60L * 1000L;
// Month names
protected final static String[] _months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
"Nov", "Dec" };
// Machine listing date/time formatters
protected final static SimpleDateFormat _mlstFormat = new SimpleDateFormat( "yyyyMMddHHmmss");
protected final static SimpleDateFormat _mlstFormatLong = new SimpleDateFormat( "yyyyMMddHHmmss.SSS");
/**
* Pack a date string in Unix format The format is 'Mmm dd hh:mm' if the file is less than six
* months old, else the format is 'Mmm dd yyyy'.
*
* @param buf StringBuilder
* @param dt Date
*/
public final static void packUnixDate(StringBuilder buf, Date dt)
{
// Check if the date is valid
if (dt == null)
{
buf.append("------------");
return;
}
// Get the time raw value
long timeVal = dt.getTime();
if (timeVal < 0)
{
buf.append("------------");
return;
}
// Add the month name and date parts to the string
Calendar cal = new GregorianCalendar();
cal.setTime(dt);
buf.append(_months[cal.get(Calendar.MONTH)]);
buf.append(" ");
int dayOfMonth = cal.get(Calendar.DATE);
if (dayOfMonth < 10)
buf.append(" ");
buf.append(dayOfMonth);
buf.append(" ");
// If the file is less than six months old we append the file time, else we append the year
long timeNow = System.currentTimeMillis();
if (Math.abs(timeNow - timeVal) > SIX_MONTHS)
{
// Append the year
buf.append(cal.get(Calendar.YEAR));
}
else
{
// Append the file time as hh:mm
int hr = cal.get(Calendar.HOUR_OF_DAY);
if (hr < 10)
buf.append("0");
buf.append(hr);
buf.append(":");
int min = cal.get(Calendar.MINUTE);
if (min < 10)
buf.append("0");
buf.append(min);
}
}
/**
* Return a machine listing date/time, in the format 'YYYYMMDDHHSS'.
*
* @param dateTime long
* @return String
*/
public final static String packMlstDateTime( long dateTime)
{
return _mlstFormat.format( new Date( dateTime));
}
/**
* Return a machine listing date/time, in the format 'YYYYMMDDHHSS.sss'.
*
* @param dateTime long
* @return String
*/
public final static String packMlstDateTimeLong( long dateTime)
{
return _mlstFormatLong.format( new Date( dateTime));
}
}