This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
forked from TeamNewPipe/NewPipe
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SponsorBlock: Merge branch 'dev' into sponsorblock
# Conflicts: # app/src/main/res/values/strings.xml
- Loading branch information
Showing
64 changed files
with
1,809 additions
and
1,283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 22 additions & 3 deletions
25
app/src/main/java/org/schabi/newpipe/ktx/OffsetDateTime.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
package org.schabi.newpipe.ktx | ||
|
||
import java.time.OffsetDateTime | ||
import java.time.ZoneId | ||
import java.time.ZoneOffset | ||
import java.time.temporal.ChronoField | ||
import java.util.Calendar | ||
import java.util.Date | ||
import java.util.GregorianCalendar | ||
import java.util.TimeZone | ||
|
||
fun OffsetDateTime.toCalendar(zoneId: ZoneId = ZoneId.systemDefault()): Calendar { | ||
return GregorianCalendar.from(if (zoneId != offset) atZoneSameInstant(zoneId) else toZonedDateTime()) | ||
// This method is a modified version of GregorianCalendar.from(ZonedDateTime). | ||
// Math.addExact() and Math.multiplyExact() are desugared even though lint displays a warning. | ||
@SuppressWarnings("NewApi") | ||
fun OffsetDateTime.toCalendar(): Calendar { | ||
val cal = GregorianCalendar(TimeZone.getTimeZone("UTC")) | ||
val offsetDateTimeUTC = withOffsetSameInstant(ZoneOffset.UTC) | ||
cal.gregorianChange = Date(Long.MIN_VALUE) | ||
cal.firstDayOfWeek = Calendar.MONDAY | ||
cal.minimalDaysInFirstWeek = 4 | ||
try { | ||
cal.timeInMillis = Math.addExact( | ||
Math.multiplyExact(offsetDateTimeUTC.toEpochSecond(), 1000), | ||
offsetDateTimeUTC[ChronoField.MILLI_OF_SECOND].toLong() | ||
) | ||
} catch (ex: ArithmeticException) { | ||
throw IllegalArgumentException(ex) | ||
} | ||
return cal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.