Skip to content

Commit bf1e9eb

Browse files
author
alexeykachalov
committed
Add method for converting windows time from SafeArray to Java Date
1 parent 8c5ebe7 commit bf1e9eb

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

jacob/src/com/jacob/com/SafeArray.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package com.jacob.com;
2121

22+
import java.util.Date;
23+
2224
/**
2325
* This creates an array wrapper around Variant objects(?). This supports 1, 2
2426
* and n-dimensional arrays. It exists in this form because n-dimensional arrays
@@ -1063,14 +1065,36 @@ public native void setStrings(int sa_idx, int nelems, String ja[],
10631065
public native void setVariant(int indices[], Variant v);
10641066

10651067
/**
1066-
* get date from an single dimensional array
1068+
* get windows time from an single dimensional array
10671069
*
10681070
* @param sa_idx
10691071
* array index
10701072
* @return date stored in array
10711073
*/
10721074
public native double getDate(int sa_idx);
10731075

1076+
/**
1077+
* returns the Java Date contained in this array
1078+
*
1079+
* @param sa_idx1
1080+
* array index
1081+
* @return Java date stored in array
1082+
* @throws IllegalStateException
1083+
* if array is not of the requested type
1084+
*/
1085+
public Date getJavaDate(int sa_idx1) {
1086+
Date returnDate = null;
1087+
if (this.getvt() == Variant.VariantDate) {
1088+
double windowsDate = this.getDate(sa_idx1);
1089+
if (windowsDate != 0.0D) {
1090+
returnDate = DateUtilities.convertWindowsTimeToDate(windowsDate);
1091+
}
1092+
return returnDate;
1093+
} else {
1094+
throw new IllegalStateException("getJavaDate() only legal on SafeArray of type VariantDate, not " + this.getvt());
1095+
}
1096+
}
1097+
10741098
/**
10751099
* variant access
10761100
*

0 commit comments

Comments
 (0)