mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
107
source/java/org/alfresco/filesys/ftp/FTPDate.java
Normal file
107
source/java/org/alfresco/filesys/ftp/FTPDate.java
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.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" };
|
||||
|
||||
/**
|
||||
* 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 StringBuffer
|
||||
* @param dt Date
|
||||
*/
|
||||
public final static void packUnixDate(StringBuffer 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 sec = cal.get(Calendar.SECOND);
|
||||
if (sec < 10)
|
||||
buf.append("0");
|
||||
buf.append(sec);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user