Skip to content

Fix both timezone problem and saved date problem #5019

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

Merged

Conversation

neslihanturan
Copy link
Collaborator

Description (required)

Fixes #1971

  • ExifInterface.TAG_DATETIME_ORIGINAL used instead of getDateTime() so that we will reach to date of creation of file
  • Date is stored in string form instead of Date data type, so timezones are never involved

Tests performed (required)

Tested ProdDebug on Pixel 5 with API level 31

Here is the test upload: https://commons.wikimedia.org/wiki/File%3ACommons_app_exif_issue.jpg

The same upload without changes in this PR: https://commons.wikimedia.org/w/index.php?title=File:Vinkeveen,_Heilig_Hart_van_Jezus_(32).jpg

Auto added categories is not tested yet.

@neslihanturan
Copy link
Collaborator Author

Thanks for the reviews @nicolas-raoul :) Now ready to be tested

// See issue https://github.com/commons-app/apps-android-commons/issues/1971
String dateTimeSubString = exif.getAttribute(ExifInterface.TAG_DATETIME_ORIGINAL);

String year = dateTimeSubString.substring(0,4);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAttribute may return null, so I think you will need to check that first.

(I would personally prefer checking the size than catching IndexOutOfBoundsException, but that's not a huge issue anyway.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a sample file without EXIF - trying to upload this gave a NullPointerException when I tested.

@misaochan
Copy link
Member

misaochan commented Jul 30, 2022

Thanks for the PR @neslihanturan ! I will test ASAP, but in the meantime I did notice that the format of the date that we are outputting in the template at https://commons.wikimedia.org/wiki/File%3ACommons_app_exif_issue.jpg "2022:07:03 (according to Exif data)" is somewhat unusual. @nicolas-raoul @whym do we know if this format is acceptable for the template?

It definitely doesn't work with the category, as Photographs taken on 2022:07:03 leads to an invalid link (but I am aware that that is still work in progress).

@whym
Copy link
Collaborator

whym commented Jul 30, 2022

Yeah, the end result should look like "{{According to Exif data|2022-07-03}}". (=joined by "-", and zero padded) In the source code it will look like

-            String dateCreatedString = year+":"+month+":"+day;
+            String dateCreatedString = String.format("%04d-%02d-%02d", Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));

(combining the preceding 3 parseInt lines into one)

This would be in line with the "yyyy-MM-dd" format already used elsewhere in the app's codebase.

(That said, the template could be made more flexible to accept different formats, if there is a legitimate need to do so, by submitting an edit request at https://commons.wikimedia.org/wiki/Template_talk:According_to_Exif_data .)

@nicolas-raoul
Copy link
Member

Here is my test with a picture taken after 3pm JST: https://commons.wikimedia.org/wiki/File:Motomiya,_Tsurumi.jpg
As you can see {{According to Exif data|2022:07:12}} was generated, which is the right date but with a formatting that does not seem to fit the category. So I agree with Jo and Whym :-)

@misaochan misaochan requested review from nicolas-raoul and whym August 2, 2022 10:28
Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@whym whym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I tested it again with betaDebug and prodDebug and there was no NullPointerException anymore. Thanks @neslihanturan !

Copy link
Member

@misaochan misaochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with prodDebug on Samsung Galaxy S20FE, works well for me. Nice work @neslihanturan ! :) I uploaded https://commons.wikimedia.org/wiki/File:Roma_Street_Parkland.jpg with edits (for Issue 1) and the correct date is used. I also uploaded a photo taken at 4.25pm (my timezone is +10 UTC) and the date is also correct there https://commons.wikimedia.org/wiki/File:Koala_22.jpg .

@misaochan misaochan merged commit 98143aa into commons-app:4.0-release Aug 3, 2022
@misaochan misaochan changed the title [WIP] Fix both timezone problem and saved date problem Fix both timezone problem and saved date problem Aug 3, 2022
misaochan added a commit that referenced this pull request Aug 8, 2022
* Fix string for custom selector

* Fix bug #4950 back arrow still present on top-level activity (#4952)

* Fix bug #4949 by correctly setting previous db version number (#4956)

* Fix bug #4949 by correctly setting previous db version number

* Fix failing tests

* Fix bug #4959 by correctly setting previous db version number and updating the current db version (#4960)

* Fix bug #4957 (#4961)

* Update library to new version that handles older Java VMs

Fixes #4972 I believe.

* Versioning for v4.0.0

* Changelog for v4.0.0

* Fix bug #4984 Added queries for package name for Android API 30+ (#4987)

* Update mapbox sdk version (#4989)

* Versioning for v4.0.1

* Changelog for v4.0.1

* Remove network type information from NetworkUtils (#4996)

* Remove network type information from NetworkUtils

* Ignore dependent tests

* Fix #4992 invert the equals condition to be null safe (#4995)

* Fix java.lang.NullPointerException for username in ContributionBoundaryCallback (#5003)

* Fix failing tests for PR #5003 (#5004)

* Fix java.lang.NullPointerException for username in ContributionBoundaryCallback

* Fix failing tests

* Update Room DB Version (#5011)

* Fix #5001 (#5010)

* Fix DB update issue (#5016)

* [WIP] Fix both timezone problem and saved date problem (#5019)

* Fix both timezone problem and saved date problem

* Fixaccidental test code and add comments

* Add issue link to the comments

* Fix format issue and null checks

* Versioning for v4.0.2

* Changelog for v4.0.2

* Add "Report Violation" menu option (#5025)

* Add "Report Violation" menu option

* Update email template

* Update email address

* Fixed typo

Co-authored-by: Josephine Lim <josephinelim86@gmail.com>

* Versioning for v4.0.3

* Changelog for v4.0.3

Co-authored-by: Josephine Lim <josephinelim86@gmail.com>
Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
Co-authored-by: neslihanturan <tur.neslihan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants