-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3098 from nightscout/dev
3.2.0.3
- Loading branch information
Showing
102 changed files
with
2,699 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ version: 2.1 | |
# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects. | ||
orbs: | ||
android: circleci/[email protected] | ||
codecov: codecov/codecov@3.2.4 | ||
codecov: codecov/codecov@3.3.0 | ||
|
||
jobs: | ||
# Below is the definition of your job to build and test your app, you can rename and customize it as you want. | ||
|
@@ -14,7 +14,7 @@ jobs: | |
executor: | ||
name: android/android-machine | ||
resource-class: large | ||
tag: 2023.07.1 | ||
tag: 2023.11.1 | ||
|
||
steps: | ||
- checkout | ||
|
@@ -34,11 +34,19 @@ jobs: | |
- android/run-tests: | ||
test-command: ./gradlew --stacktrace jacocoAllDebugReport | ||
|
||
# And finally run the release build | ||
# - run: | ||
# name: Assemble release build | ||
# command: | | ||
# ./gradlew assembleRelease | ||
- run: | ||
name: Save test results | ||
command: | | ||
mkdir -p ~/test-results/junit/ | ||
find . -type f -regex ".*/build/outputs/androidTest-results/.*xml" -exec cp {} ~/test-results/junit/ \; | ||
when: always | ||
|
||
- store_test_results: | ||
path: ~/test-results | ||
|
||
- store_artifacts: | ||
path: ~/test-results/junit | ||
|
||
- codecov/upload: | ||
file: './build/reports/jacoco/jacocoAllDebugReport/jacocoAllDebugReport.xml' | ||
|
||
|
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
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
54 changes: 44 additions & 10 deletions
54
core/utils/src/main/kotlin/app/aaps/core/utils/MidnightUtils.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,22 +1,56 @@ | ||
package app.aaps.core.utils | ||
|
||
import org.joda.time.DateTime | ||
import java.time.Duration | ||
import java.time.Instant | ||
import java.time.ZoneId | ||
import java.time.ZonedDateTime | ||
|
||
object MidnightUtils { | ||
/* | ||
/** | ||
* Midnight time conversion | ||
*/ | ||
object MidnightUtils { | ||
|
||
/** | ||
* Actual passed seconds from midnight ignoring DST change | ||
* (thus always having 24 hours in a day, not 23 or 25 in days where DST changes) | ||
* | ||
* @return seconds | ||
*/ | ||
fun secondsFromMidnight(): Int { | ||
val passed = DateTime().millisOfDay.toLong() | ||
return (passed / 1000).toInt() | ||
val nowZoned = ZonedDateTime.now() | ||
val localTime = nowZoned.toLocalTime() | ||
val midnight = nowZoned.toLocalDate().atStartOfDay(nowZoned.zone).toLocalTime() | ||
val duration = Duration.between(midnight, localTime) | ||
return duration.seconds.toInt() | ||
} | ||
|
||
fun secondsFromMidnight(date: Long): Int { | ||
val passed = DateTime(date).millisOfDay.toLong() | ||
return (passed / 1000).toInt() | ||
/** | ||
* Passed seconds from midnight for specified time ignoring DST change | ||
* (thus always having 24 hours in a day, not 23 or 25 in days where DST changes) | ||
* | ||
* @param timestamp time | ||
* @return seconds | ||
*/ | ||
fun secondsFromMidnight(timestamp: Long): Int { | ||
val timeZoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()) | ||
val localTime = timeZoned.toLocalTime() | ||
val midnight = timeZoned.toLocalDate().atStartOfDay(timeZoned.zone).toLocalTime() | ||
val duration: Duration = Duration.between(midnight, localTime) | ||
return duration.seconds.toInt() | ||
} | ||
|
||
fun milliSecFromMidnight(date: Long): Long { | ||
return DateTime(date).millisOfDay.toLong() | ||
/** | ||
* Passed milliseconds from midnight for specified time ignoring DST change | ||
* (thus always having 24 hours in a day, not 23 or 25 in days where DST changes) | ||
* | ||
* @param timestamp time | ||
* @return milliseconds | ||
*/ | ||
fun milliSecFromMidnight(timestamp: Long): Long { | ||
val timeZoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()) | ||
val localTime = timeZoned.toLocalTime() | ||
val midnight = timeZoned.toLocalDate().atStartOfDay(timeZoned.zone).toLocalTime() | ||
val duration = Duration.between(midnight, localTime) | ||
return duration.toMillis() | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
core/utils/src/test/kotlin/app/aaps/core/utils/MidnightUtilsTest.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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package app.aaps.core.utils | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.ZoneId | ||
import java.time.ZonedDateTime | ||
import java.util.TimeZone | ||
|
||
class MidnightUtilsTest { | ||
|
||
@BeforeEach fun setUp() { | ||
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Amsterdam")) | ||
} | ||
|
||
@Test | ||
fun secondsFromMidnight() { | ||
val time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(time)).isIn(0..24 * 3600) | ||
} | ||
|
||
@Test | ||
fun testSecondsFromMidnight() { | ||
val midnight = LocalDate.now().atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(midnight)).isEqualTo(0) | ||
val oneHourAfter = LocalDateTime.ofInstant(Instant.ofEpochMilli(midnight), ZoneId.systemDefault()).atZone(ZoneId.systemDefault()).plusHours(1).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(oneHourAfter)).isEqualTo(3600) | ||
} | ||
|
||
@Test | ||
fun milliSecFromMidnight() { | ||
val midnight = LocalDate.now().atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(midnight)).isEqualTo(0) | ||
val oneHourAfter = LocalDateTime.ofInstant(Instant.ofEpochMilli(midnight), ZoneId.systemDefault()).atZone(ZoneId.systemDefault()).plusHours(1).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.milliSecFromMidnight(oneHourAfter)).isEqualTo(3600 * 1000) | ||
} | ||
|
||
@Test fun testDateTimeToDuration() { | ||
val dateTime = ZonedDateTime.of(1991, 8, 13, 23, 5, 1, 0, ZoneId.of("Europe/Amsterdam")).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101) | ||
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L) | ||
} | ||
|
||
@Test fun testDateTimeToDurationAtDstChange() { | ||
val dateTime = ZonedDateTime.of(2020, 10, 25, 23, 5, 1, 0, ZoneId.of("Europe/Amsterdam")).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101) | ||
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L) | ||
} | ||
|
||
@Test fun testDateTimeToDurationAtDstReverseChange() { | ||
val dateTime = ZonedDateTime.of(2020, 3, 29, 23, 5, 1, 0, ZoneId.of("Europe/Amsterdam")).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101) | ||
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L) | ||
} | ||
|
||
@Test fun testDateTimeInOtherZone() { | ||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")) | ||
assertThat(ZoneId.systemDefault().id).isEqualTo("America/Los_Angeles") | ||
val dateTime = ZonedDateTime.of(2020, 3, 29, 23, 5, 1, 0, ZoneId.of("America/Los_Angeles")).toInstant().toEpochMilli() | ||
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101) | ||
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L) | ||
} | ||
} |
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.