format date of comment published. changed default instance

This commit is contained in:
Ritvik Saraf 2018-12-26 11:08:39 +05:30
parent df0db8468d
commit 8755c25349
2 changed files with 18 additions and 2 deletions

View file

@ -18,7 +18,7 @@ public class PeertubeInstance {
private final String url;
private String name;
public static final PeertubeInstance defaultInstance = new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host");
public static final PeertubeInstance defaultInstance = new PeertubeInstance("https://framatube.org", "FramaTube");
public PeertubeInstance(String url) throws IOException {
this.url = url;

View file

@ -1,5 +1,10 @@
package org.schabi.newpipe.extractor.services.peertube.extractors;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.comments.CommentsInfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -42,7 +47,8 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
@Override
public String getPublishedTime() throws ParsingException {
return JsonUtils.getString(item, "createdAt");
String date = JsonUtils.getString(item, "createdAt");
return getFormattedDate(date);
}
@Override
@ -85,4 +91,14 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
return PeertubeChannelLinkHandlerFactory.getInstance().fromId(name + "@" + host).getUrl();
}
private String getFormattedDate(String date) {
DateFormat sourceDf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
DateFormat targetDf = new SimpleDateFormat("dd-MM-yyyy hh:mm a", Locale.ENGLISH);
try {
return targetDf.format(sourceDf.parse(date));
} catch (ParseException e) {
return date;
}
}
}