01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hwpf.usermodel;
19:
20: import org.apache.poi.util.BitField;
21: import org.apache.poi.util.BitFieldFactory;
22: import org.apache.poi.util.LittleEndian;
23:
24: /**
25: * This class is used to represent a date and time in a Word document.
26: *
27: * @author Ryan Ackley
28: */
29: public class DateAndTime implements Cloneable {
30: public static final int SIZE = 4;
31: private short _info;
32: private static final BitField _minutes = BitFieldFactory
33: .getInstance(0x3f);
34: private static final BitField _hours = BitFieldFactory
35: .getInstance(0x7c0);
36: private static final BitField _dom = BitFieldFactory
37: .getInstance(0xf800);
38: private short _info2;
39: private static final BitField _months = BitFieldFactory
40: .getInstance(0xf);
41: private static final BitField _years = BitFieldFactory
42: .getInstance(0x1ff0);
43: private static final BitField _weekday = BitFieldFactory
44: .getInstance(0xe000);
45:
46: public DateAndTime() {
47: }
48:
49: public DateAndTime(byte[] buf, int offset) {
50: _info = LittleEndian.getShort(buf, offset);
51: _info2 = LittleEndian.getShort(buf, offset
52: + LittleEndian.SHORT_SIZE);
53: }
54:
55: public void serialize(byte[] buf, int offset) {
56: LittleEndian.putShort(buf, offset, _info);
57: LittleEndian.putShort(buf, offset + LittleEndian.SHORT_SIZE,
58: _info2);
59: }
60:
61: public boolean equals(Object o) {
62: DateAndTime dttm = (DateAndTime) o;
63: return _info == dttm._info && _info2 == dttm._info2;
64: }
65:
66: public Object clone() throws CloneNotSupportedException {
67: return super.clone();
68: }
69: }
|