-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import fr.free.nrw.commons.upload.FileUtils; | ||
|
@@ -124,13 +126,27 @@ private DateTimeWithSource getFileCreatedDateFromCP(Context context) { | |
private DateTimeWithSource getDateTimeFromExif() { | ||
try { | ||
ExifInterface exif = new ExifInterface(file.getAbsolutePath()); | ||
8000 | @SuppressLint("RestrictedApi") Long dateTime = exif.getDateTime(); | |
String dateTimeSubString = exif.getAttribute(ExifInterface.TAG_DATETIME_ORIGINAL); | ||
|
||
dateTimeSubString = "2022:ss:33"; | ||
String year = dateTimeSubString.substring(0,4); | ||
neslihanturan marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
Integer.parseInt(year); | ||
String month = dateTimeSubString.substring(5,7); | ||
Integer.parseInt(month); | ||
String day = dateTimeSubString.substring(8,10); | ||
Integer.parseInt(day); | ||
String dateCreatedString = year+":"+month+":"+day; | ||
@SuppressLint("RestrictedApi") Long dateTime = exif.getDateTimeOriginal(); | ||
if(dateTime != null){ | ||
Date date = new Date(dateTime); | ||
return new DateTimeWithSource(date, DateTimeWithSource.EXIF_SOURCE); | ||
return new DateTimeWithSource(date, dateCreatedString, DateTimeWithSource.EXIF_SOURCE); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} catch (NumberFormatException e) { | ||
e.printStackTrace(); | ||
} catch (IndexOutOfBoundsException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
@@ -149,6 +165,7 @@ public class DateTimeWithSource { | |
public static final String EXIF_SOURCE = "exif"; | ||
|
||
private final long epochDate; | ||
private String dateString; // this does not includes timezone information | ||
private final String source; | ||
|
||
public DateTimeWithSource(long epochDate, String source) { | ||
|
@@ -161,10 +178,20 @@ public DateTimeWithSource(Date date, String source) { | |
this.source = source; | ||
} | ||
|
||
public DateTimeWithSource(Date date, String dateString, String source) { | ||
this.epochDate = date.getTime(); | ||
this.dateString = dateString; | ||
this.source = source; | ||
} | ||
|
||
public long getEpochDate() { | ||
return epochDate; | ||
} | ||
|
||
public String getDateString() { | ||
return dateString; | ||
} | ||
|
||
public String getSource() { | ||
return source; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.