mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-16 17:55:15 +00:00
svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@5141 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V2.0@51352 . - FLOSS - Some files will need a follow-up -root/projects/repository/source/java/org/alfresco/repo/avm/wf/AVMRemoveWFStoreHandler.java (not yet on HEAD: 5094) -root/projects/repository/source/java/org/alfresco/filesys/server/state/FileStateLockManager.java (not yet on HEAD: 5093) -onContentUpdateRecord (not on HEAD) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5167 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
153 lines
4.3 KiB
Java
153 lines
4.3 KiB
Java
/*
|
|
* Copyright (C) 2005 Alfresco, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* As a special exception to the terms and conditions of version 2.0 of
|
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
|
* FLOSS exception. You should have recieved a copy of the text describing
|
|
* the FLOSS exception, and it is also available here:
|
|
* http://www.alfresco.com/legal/licensing"
|
|
*/
|
|
package org.alfresco.filesys.smb;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* SMB date/time class.
|
|
*/
|
|
public final class SMBDate extends Date
|
|
{
|
|
private static final long serialVersionUID = 3258407335553806902L;
|
|
|
|
// Constants
|
|
//
|
|
// Bit masks for extracting the date/time fields from an SMB encoded date/time.
|
|
//
|
|
|
|
private static final int Days = 0x001F;
|
|
private static final int Month = 0x01E0;
|
|
private static final int Year = 0xFE00;
|
|
|
|
private static final int TwoSeconds = 0x001F;
|
|
private static final int Minutes = 0x07E0;
|
|
private static final int Hours = 0xF800;
|
|
|
|
/**
|
|
* Construct the SMBDate using a seconds since 1-Jan-1970 00:00:00 value.
|
|
*
|
|
* @param secs Seconds since base date/time 1970 value
|
|
*/
|
|
|
|
public SMBDate(int secs)
|
|
{
|
|
super((long) (secs & 0x7FFFFFFF));
|
|
}
|
|
|
|
/**
|
|
* Construct the SMBDate using the SMB encoded date/time values.
|
|
*
|
|
* @param dat SMB encoded date value
|
|
* @param tim SMB encoded time value
|
|
*/
|
|
|
|
public SMBDate(int dat, int tim)
|
|
{
|
|
|
|
// Extract the date from the SMB encoded value
|
|
|
|
int days = dat & Days;
|
|
int months = (dat & Month) >> 5;
|
|
int year = (dat & Year) >> 9;
|
|
|
|
// Extract the time from the SMB encoded value
|
|
|
|
int secs = (tim & TwoSeconds) * 2;
|
|
int mins = (tim & Minutes) >> 5;
|
|
int hours = (tim & Hours) >> 11;
|
|
|
|
// Use a calendar object to create the date/time value
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.clear();
|
|
cal.set(year + 1980, months - 1, days, hours, mins, secs);
|
|
|
|
// Initialize this dates raw value
|
|
|
|
this.setTime(cal.getTime().getTime());
|
|
}
|
|
|
|
/**
|
|
* Create a new SMBDate using the long time value.
|
|
*
|
|
* @param dattim long
|
|
*/
|
|
public SMBDate(long dattim)
|
|
{
|
|
super(dattim);
|
|
}
|
|
|
|
/**
|
|
* Return this date as an SMB encoded date.
|
|
*
|
|
* @return SMB encoded date value.
|
|
*/
|
|
|
|
public final int asSMBDate()
|
|
{
|
|
|
|
// Use a calendar object to get the day, month and year values
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(this);
|
|
|
|
// Build the SMB encoded date value
|
|
|
|
int smbDate = cal.get(Calendar.DAY_OF_MONTH);
|
|
smbDate += (cal.get(Calendar.MONTH) + 1) << 5;
|
|
smbDate += (cal.get(Calendar.YEAR) - 1980) << 9;
|
|
|
|
// Return the SMB encoded date value
|
|
|
|
return smbDate;
|
|
}
|
|
|
|
/**
|
|
* Return this time as an SMB encoded time.
|
|
*
|
|
* @return SMB encoded time value.
|
|
*/
|
|
|
|
public final int asSMBTime()
|
|
{
|
|
|
|
// Use a calendar object to get the hour, minutes and seconds values
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
cal.setTime(this);
|
|
|
|
// Build the SMB encoded time value
|
|
|
|
int smbTime = cal.get(Calendar.SECOND) / 2;
|
|
smbTime += cal.get(Calendar.MINUTE) << 5;
|
|
smbTime += cal.get(Calendar.HOUR_OF_DAY) << 11;
|
|
|
|
// Return the SMB encoded time value
|
|
|
|
return smbTime;
|
|
}
|
|
} |