Skip to content

Commit e26cc84

Browse files
Added documentation for parsing methods
1 parent fa4b717 commit e26cc84

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • extractor/src/main/java/org/schabi/newpipe/extractor/localization

extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.schabi.newpipe.extractor.exceptions.ParsingException;
44

55
import javax.annotation.Nonnull;
6+
import javax.annotation.Nullable;
67
import java.io.Serializable;
78
import java.time.Instant;
89
import java.time.LocalDateTime;
@@ -90,6 +91,15 @@ public String toString() {
9091
+ '}';
9192
}
9293

94+
/**
95+
* Parses a date string that matches the ISO-8601 {@link OffsetDateTime} pattern, e.g.
96+
* "2011-12-03T10:15:30+01:00".
97+
*
98+
* @param date The date string
99+
* @return a non-approximate {@link DateWrapper}, or null if the string is null
100+
* @throws ParsingException if the string does not match the expected format
101+
*/
102+
@Nullable
93103
public static DateWrapper fromOffsetDateTime(final String date) throws ParsingException {
94104
try {
95105
return date != null ? new DateWrapper(OffsetDateTime.parse(date)) : null;
@@ -98,6 +108,15 @@ public static DateWrapper fromOffsetDateTime(final String date) throws ParsingEx
98108
}
99109
}
100110

111+
/**
112+
* Parses a date string that matches the ISO-8601 {@link Instant} pattern, e.g.
113+
* "2011-12-03T10:15:30Z".
114+
*
115+
* @param date The date string
116+
* @return a non-approximate {@link DateWrapper}, or null if the string is null
117+
* @throws ParsingException if the string does not match the expected format
118+
*/
119+
@Nullable
101120
public static DateWrapper fromInstant(final String date) throws ParsingException {
102121
try {
103122
return date != null ? new DateWrapper(Instant.parse(date)) : null;

0 commit comments

Comments
 (0)