-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OaIdl.DATE(Date javaDate) sets wrong date in some cases #1460
Comments
Java time has no concept of DST, so the first hour of the day ends up being the "last hour" of a 24 hour period with reference to the epoch, as assumed in this calculation: jna/contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java Lines 266 to 267 in 0444bf9
However, this may be by design, per the Windows docs for DATE:
One would reason based on that last sentence that it is an error to use a DST-impacted Java |
Any reason not to use ZonedDateTime for the conversion from UTC to local time, rather than the above calculation? |
It requires JDK 8. We maintain (at least in 5.X series) compatibility with JDK 6. |
Apache POI has solved it here using |
Thanks for the info. Very interesting. Here's the latest version: https://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/DateUtil.java?view=markup Can I contribute a fix based on this? |
Please do. Also a test case failing in the existing setup and passing with the fix would be helpful. |
Please note, that your fix must be created by you. You can not copy from Apache POI. JNA is dual licensed ALv2 + LGPL, so pure ALv2 can't be integrated.
|
Agree that you cannot copy, but there are other factors to consider (POI is based on Jan 1 1900 epoch, |
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | compile | minor | `5.12.1` -> `5.13.0` | --- ### Release Notes <details> <summary>java-native-access/jna</summary> ### [`v5.13.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5130) [Compare Source](java-native-access/jna@5.12.1...5.13.0) \================ ## Features - [#​1454](java-native-access/jna#1454): Add `c.s.j.p.win32.Psapi.QueryWorkingSetEx` and associated Types - [@​crain-32](https://github.com/Crain-32). - [#​1459](java-native-access/jna#1459): Add `VirtualLock` and `VirtualUnlock` in `c.s.j.p.win32.Kernel32` - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1471](java-native-access/jna#1471): Add `c.s.j.p.win32.Advapi32Util#isCurrentProcessElevated` and associated Types - [@​dbwiddis](https://github.com/dbwiddis). - [#​1474](java-native-access/jna#1474): Add `c.s.j.p.win32.WbemCli#IWbemClassObject.IWbemQualifierSet`, `IWbemServices.GetObject`, `IWbemContext.SetValue` and associated methods - [@​rchateauneu](https://github.com/rchateauneu). - [#​1482](java-native-access/jna#1482): Add multilingual support of `Kernel32Util.formatMessage` - [@​overpathz](https://github.com/overpathz). - [#​1490](java-native-access/jna#1490): Adds support for a custom `SymbolProvider` in `NativeLibrary` & `Library` - [@​soywiz](https://github.com/soywiz). - [#​1491](java-native-access/jna#1491): Update libffi to v3.4.4 - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1487](java-native-access/jna#1487): Add 'uses' information to OSGI metadata in MANIFEST.MF to improve stability of package resolution - [@​sratz](https://github.com/sratz). ## Bug Fixes - [#​1452](java-native-access/jna#1452): Fix memory allocation/handling for error message generation in native library code (`dispatch.c`) - [@​matthiasblaesing](https://github.com/matthiasblaesing). - [#​1460](java-native-access/jna#1460): Fix win32 variant date conversion in DST offest window and with millisecond values - [@​eranl](https://github.com/eranl). - [#​1472](java-native-access/jna#1472): Fix incorrect bitmask in `c.s.j.Pointer#createConstant(int)` - [@​dbwiddis](https://github.com/dbwiddis). - [#​1481](java-native-access/jna#1481): Fix NPE in NativeLibrary when unpacking from classpath is disabled - [@​trespasserw](https://github.com/trespasserw). - [#​1489](java-native-access/jna#1489): Fixes typo in `OpenGL32Util#wglGetProcAddress`, instead of parameter `procName` the hardcoded value `wglEnumGpusNV` was used - [@​soywiz](https://github.com/soywiz). </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
Version of JNA and related jars: 5.12.1
Version and vendor of the java virtual machine:
IMPLEMENTOR="Oracle Corporation"
JAVA_VERSION="17.0.1"
Operating system: Windows 7
System architecture (CPU type, bitness of the JVM): x86_64
Complete description of the problem:
When com.sun.jna.platform.win32.OaIdl.DATE(Date javaDate) is called with a javaDate whose time part converted to local time is between midnight and 1am, while DST (60-minute offset) is on, the date portion of the resulting DATE object is of the previous day, while the time portion is correct, which means that the DATE object is 24 hours behind.
Steps to reproduce:
Simple test: with DST on, instantiate one OaIdl.DATE(Date javaDate) with a javaDate having the time 12:30am local time and another with 1:30am local time, with the same date, and you'll see that the resulting DATEs have different integralParts.
The text was updated successfully, but these errors were encountered: