mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-03-30 05:55:39 +02:00
Parse time with ZonedDateTime on android O and up
This commit is contained in:
parent
3c91007d93
commit
de3bea0729
@ -11,6 +11,9 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -283,7 +286,10 @@ public class ParseComment {
|
|||||||
String authorQualifiedName = LemmyUtils.actorID2FullName(creatorObj.getString("actor_id"));
|
String authorQualifiedName = LemmyUtils.actorID2FullName(creatorObj.getString("actor_id"));
|
||||||
String linkAuthor = creatorObj.getString("actor_id");
|
String linkAuthor = creatorObj.getString("actor_id");
|
||||||
long commentTimeMillis = 0;
|
long commentTimeMillis = 0;
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
|
commentTimeMillis = ZonedDateTime.parse(commentObj.getString("published"),
|
||||||
|
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("Z"))).toInstant().toEpochMilli();
|
||||||
|
} else {
|
||||||
String dateStr = commentObj.getString("published");
|
String dateStr = commentObj.getString("published");
|
||||||
|
|
||||||
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
||||||
@ -297,6 +303,7 @@ public class ParseComment {
|
|||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
String content = MarkdownUtils.processImageCaptions(commentObj.getString("content"), "Image");
|
String content = MarkdownUtils.processImageCaptions(commentObj.getString("content"), "Image");
|
||||||
String commentMarkdown = content;
|
String commentMarkdown = content;
|
||||||
String commentRawText = content;
|
String commentRawText = content;
|
||||||
|
@ -20,6 +20,9 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -154,7 +157,10 @@ public class ParsePost {
|
|||||||
String author = creator.getString("name");
|
String author = creator.getString("name");
|
||||||
String authorFull = LemmyUtils.actorID2FullName(creator.getString("actor_id"));
|
String authorFull = LemmyUtils.actorID2FullName(creator.getString("actor_id"));
|
||||||
long postTimeMillis = 0;
|
long postTimeMillis = 0;
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
|
postTimeMillis = ZonedDateTime.parse(post.getString("published"),
|
||||||
|
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("Z"))).toInstant().toEpochMilli();
|
||||||
|
} else {
|
||||||
String dateStr = post.getString("published");
|
String dateStr = post.getString("published");
|
||||||
|
|
||||||
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
||||||
@ -168,6 +174,7 @@ public class ParsePost {
|
|||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String title = post.getString("name");
|
String title = post.getString("name");
|
||||||
String permalink = post.getString("ap_id");
|
String permalink = post.getString("ap_id");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user