Closed Kumotaku closed 5 months ago
Yes, many cameras don't even write timezone information.
It's best to just ignore time zones and display exactly the date as shown in the EXIF.
Edit: But I think that would be too much of a change by now considering the user base. So I would not recommend it.
@Kumotaku thank you for reporting this.
I'm hoping you and/or @StefanOltmann can advise what the best approach would be here.
If we don't set unknown dates to GMT then unit tests fail. For example here in AEDT:
_directory.setString(1, "2002:01:30 23:59:59");
java.util.Date date = _directory.getDate(1, null);
java.lang.AssertionError:
Expected :Thu Jan 31 10:59:59 AEDT 2002
Actual :Wed Jan 30 23:59:59 AEDT 2002
I'm not very familiar with Java these days. What would be the best approach here, given we want both maximal information and a good experience for library users, and stable unit tests.
@drewnoakes
I am sure you wonโt like my approach. ๐
This global variable is set from the unit tests. And yes, a user could set it at runtime and corrupt the results. As an alternative I can think of a environment variable that controls this.
Looking at the code I see that you already solved this for the PNG tests by just setting the default TimeZone to GMT there.
I will craft a PR and try the same for the other unit tests.
The TimeZone
class has both getDefault()
and setDefault(zone)
. setDefault()
overrides the timezone retrieved from the OS for that JVM instance as I understand it. Thus, this should only apply "until the end of the application execution".
Wouldn't it be best to simply apply getDefault()
when the timezone is missing, assuming that the computer and image belongs to the same geographical area - and then "prime" the test run with a call to setDefault(GMT)
to in effect make sure that "unknown" timezones are always GMT during test runs?
@StefanOltmann You post popped up in the moment I pressed comment
. But yeah, the idea is the same ๐
@drewnoakes Your PR is ready. :)
@Nadahar Setting the default time zone to a new value just for the test is the best solution, indeed.
I wish I could do the same for my lib, but it's written in Kotlin. So I use kotlinx-datetime, which does not expose setDefault(zone)
as not all platforms that I target allow this. Maybe that's the reason I was not thinking of that first.
Thank you @StefanOltmann and @Nadahar, the approach in PR looks great. Merged.
date time shown with windows explorer:![image](https://github.com/drewnoakes/metadata-extractor/assets/44130556/e9df9a38-98d7-43af-8941-71f3733c364e)
but read this:![image](https://github.com/drewnoakes/metadata-extractor/assets/44130556/598e164c-b647-488e-98a0-5c16bf7e57e9)
btw, i'm in China. timezone is gmt+8.00
i suggest not to set timezone here:![image](https://github.com/drewnoakes/metadata-extractor/assets/44130556/b5bd8b6c-74ff-426d-92a1-14d6f6e0200e)