1 19 20 package jxl.read.biff; 21 22 import java.util.Date ; 23 import java.util.TimeZone ; 24 import java.text.SimpleDateFormat ; 25 import java.text.DateFormat ; 26 27 import common.Assert; 28 import common.Logger; 29 30 import jxl.NumberCell; 31 import jxl.DateCell; 32 import jxl.CellType; 33 import jxl.CellFeatures; 34 import jxl.format.CellFormat; 35 import jxl.biff.FormattingRecords; 36 37 40 class DateRecord implements DateCell, CellFeaturesAccessor 41 { 42 45 private static Logger logger = Logger.getLogger(DateRecord.class); 46 47 50 private Date date; 51 54 private int row; 55 58 private int column; 59 60 63 private boolean time; 64 65 68 private DateFormat format; 69 70 73 private CellFormat cellFormat; 74 75 78 private int xfIndex; 79 80 83 private FormattingRecords formattingRecords; 84 85 88 private SheetImpl sheet; 89 90 93 private CellFeatures features; 94 95 96 100 private boolean initialized; 101 102 private static final SimpleDateFormat dateFormat = 104 new SimpleDateFormat ("dd MMM yyyy"); 105 106 private static final SimpleDateFormat timeFormat = 107 new SimpleDateFormat ("HH:mm:ss"); 108 109 private static final int nonLeapDay = 61; 114 115 private static final TimeZone gmtZone = TimeZone.getTimeZone("GMT"); 116 117 private static final int utcOffsetDays = 25569; 120 121 private static final int utcOffsetDays1904 = 24107; 124 125 private static final long msInADay = 24 * 60 * 60 * 1000; 127 128 137 public DateRecord(NumberCell num, 138 int xfi, FormattingRecords fr, 139 boolean nf, SheetImpl si) 140 { 141 row = num.getRow(); 142 column = num.getColumn(); 143 xfIndex = xfi; 144 formattingRecords = fr; 145 sheet = si; 146 initialized = false; 147 148 format = formattingRecords.getDateFormat(xfIndex); 149 150 double numValue = num.getValue(); 152 153 if (Math.abs(numValue) < 1) 154 { 155 if (format == null) 156 { 157 format = timeFormat; 158 } 159 time = true; 160 } 161 else 162 { 163 if (format == null) 164 { 165 format = dateFormat; 166 } 167 time = false; 168 } 169 170 if (!nf && !time && numValue < nonLeapDay) 175 { 176 numValue += 1; 177 } 178 179 format.setTimeZone(gmtZone); 182 183 int offsetDays = nf ? utcOffsetDays1904 : utcOffsetDays; 185 double utcDays = numValue - offsetDays; 186 187 long utcValue = Math.round(utcDays * msInADay); 190 191 date = new Date (utcValue); 192 } 193 194 199 public final int getRow() 200 { 201 return row; 202 } 203 204 209 public final int getColumn() 210 { 211 return column; 212 } 213 214 219 public Date getDate() 220 { 221 return date; 222 } 223 224 230 public String getContents() 231 { 232 return format.format(date); 233 } 234 235 240 public CellType getType() 241 { 242 return CellType.DATE; 243 } 244 245 251 public boolean isTime() 252 { 253 return time; 254 } 255 256 264 public DateFormat getDateFormat() 265 { 266 Assert.verify(format != null); 267 268 return format; 269 } 270 271 277 public CellFormat getCellFormat() 278 { 279 if (!initialized) 280 { 281 cellFormat = formattingRecords.getXFRecord(xfIndex); 282 initialized = true; 283 } 284 285 return cellFormat; 286 } 287 288 293 public boolean isHidden() 294 { 295 ColumnInfoRecord cir = sheet.getColumnInfo(column); 296 297 if (cir != null && cir.getWidth() == 0) 298 { 299 return true; 300 } 301 302 RowRecord rr = sheet.getRowInfo(row); 303 304 if (rr != null && (rr.getRowHeight() == 0 || rr.isCollapsed())) 305 { 306 return true; 307 } 308 309 return false; 310 } 311 312 317 protected final SheetImpl getSheet() 318 { 319 return sheet; 320 } 321 322 327 public CellFeatures getCellFeatures() 328 { 329 return features; 330 } 331 332 337 public void setCellFeatures(CellFeatures cf) 338 { 339 features = cf; 340 } 341 342 } 343 344 345 346 347 348 | Popular Tags |