-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Metadata.java
46 lines (36 loc) · 1.23 KB
/
Metadata.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.imagepicker;
import android.util.Log;
import androidx.annotation.Nullable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
abstract class Metadata {
protected String datetime;
protected int height;
protected int width;
abstract public String getDateTime();
abstract public int getWidth();
abstract public int getHeight();
/**
* Converts a timestamp to a UTC timestamp
*
* @param value - timestamp
* @param format - input format
* @return formatted timestamp
*/
protected @Nullable
String getDateTimeInUTC(String value, String format) {
try {
Date datetime = new SimpleDateFormat(format, Locale.US).parse(value);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
if (datetime != null) {
return formatter.format(datetime);
}
return null;
} catch (Exception e) {
// This error does not bubble up to RN as we don't want failed datetime parsing to prevent selection
Log.e("RNIP", "Could not parse image datetime to UTC: " + e.getMessage());
return null;
}
}
}