1 17 package org.alfresco.filesys.smb; 18 19 import java.util.Calendar ; 20 import java.util.Date ; 21 22 25 public final class SMBDate extends Date 26 { 27 private static final long serialVersionUID = 3258407335553806902L; 28 29 34 private static final int Days = 0x001F; 35 private static final int Month = 0x01E0; 36 private static final int Year = 0xFE00; 37 38 private static final int TwoSeconds = 0x001F; 39 private static final int Minutes = 0x07E0; 40 private static final int Hours = 0xF800; 41 42 47 48 public SMBDate(int secs) 49 { 50 super((long) (secs & 0x7FFFFFFF)); 51 } 52 53 59 60 public SMBDate(int dat, int tim) 61 { 62 63 65 int days = dat & Days; 66 int months = (dat & Month) >> 5; 67 int year = (dat & Year) >> 9; 68 69 71 int secs = (tim & TwoSeconds) * 2; 72 int mins = (tim & Minutes) >> 5; 73 int hours = (tim & Hours) >> 11; 74 75 77 Calendar cal = Calendar.getInstance(); 78 cal.clear(); 79 cal.set(year + 1980, months - 1, days, hours, mins, secs); 80 81 83 this.setTime(cal.getTime().getTime()); 84 } 85 86 91 public SMBDate(long dattim) 92 { 93 super(dattim); 94 } 95 96 101 102 public final int asSMBDate() 103 { 104 105 107 Calendar cal = Calendar.getInstance(); 108 cal.setTime(this); 109 110 112 int smbDate = cal.get(Calendar.DAY_OF_MONTH); 113 smbDate += (cal.get(Calendar.MONTH) + 1) << 5; 114 smbDate += (cal.get(Calendar.YEAR) - 1980) << 9; 115 116 118 return smbDate; 119 } 120 121 126 127 public final int asSMBTime() 128 { 129 130 132 Calendar cal = Calendar.getInstance(); 133 cal.setTime(this); 134 135 137 int smbTime = cal.get(Calendar.SECOND) / 2; 138 smbTime += cal.get(Calendar.MINUTE) << 5; 139 smbTime += cal.get(Calendar.HOUR_OF_DAY) << 11; 140 141 143 return smbTime; 144 } 145 } | Popular Tags |