#637 fixed writing incorrect OffsetTime tag when timezone is negative
This commit is contained in:
parent
a4e5748ced
commit
94647a928b
2 changed files with 29 additions and 5 deletions
|
@ -52,6 +52,7 @@ import pixy.meta.meta.MetadataType
|
|||
import java.io.*
|
||||
import java.nio.channels.Channels
|
||||
import java.util.*
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
abstract class ImageProvider {
|
||||
open fun fetchSingle(context: Context, uri: Uri, sourceMimeType: String?, callback: ImageOpCallback) {
|
||||
|
@ -538,11 +539,7 @@ abstract class ImageProvider {
|
|||
exif.setAttribute(ExifInterface.TAG_DATETIME, dateString)
|
||||
exif.setAttribute(ExifInterface.TAG_DATETIME_ORIGINAL, dateString)
|
||||
|
||||
val offsetInMinutes = TimeZone.getDefault().getOffset(dateTimeMillis) / 60000
|
||||
val offsetSign = if (offsetInMinutes < 0) "-" else "+"
|
||||
val offsetHours = "${offsetInMinutes / 60}".padStart(2, '0')
|
||||
val offsetMinutes = "${offsetInMinutes % 60}".padStart(2, '0')
|
||||
val timeZoneString = "$offsetSign$offsetHours:$offsetMinutes"
|
||||
val timeZoneString = getTimeZoneString(TimeZone.getDefault(), dateTimeMillis)
|
||||
exif.setAttribute(ExifInterface.TAG_OFFSET_TIME, timeZoneString)
|
||||
exif.setAttribute(ExifInterface.TAG_OFFSET_TIME_ORIGINAL, timeZoneString)
|
||||
|
||||
|
@ -1387,6 +1384,15 @@ abstract class ImageProvider {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun getTimeZoneString(timeZone: TimeZone, dateTimeMillis: Long): String {
|
||||
val offset = timeZone.getOffset(dateTimeMillis)
|
||||
val offsetInMinutes = offset.absoluteValue / 60000
|
||||
val offsetSign = if (offset < 0) "-" else "+"
|
||||
val offsetHours = "${offsetInMinutes / 60}".padStart(2, '0')
|
||||
val offsetMinutes = "${offsetInMinutes % 60}".padStart(2, '0')
|
||||
return "$offsetSign$offsetHours:$offsetMinutes"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package deckers.thibault.aves.model.provider
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.Month
|
||||
import java.util.TimeZone
|
||||
|
||||
class ImageProviderTest {
|
||||
@Test
|
||||
fun imageProvider_CorrectEmailSimple_ReturnsTrue() {
|
||||
val date = LocalDate.of(1990, Month.FEBRUARY, 11).toEpochDay()
|
||||
assertEquals(ImageProvider.getTimeZoneString(TimeZone.getTimeZone("Europe/Paris"), date), "+01:00")
|
||||
assertEquals(ImageProvider.getTimeZoneString(TimeZone.getTimeZone("UTC"), date), "+00:00")
|
||||
assertEquals(ImageProvider.getTimeZoneString(TimeZone.getTimeZone("Asia/Kolkata"), date), "+05:30")
|
||||
assertEquals(ImageProvider.getTimeZoneString(TimeZone.getTimeZone("America/Chicago"), date), "-06:00")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue