From 77762fca0f02272e2ba4c8acf8a0141852adf9f5 Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Fri, 29 Sep 2023 14:50:09 +0300 Subject: [PATCH] remove unused epoch converter files --- data/epoch/.gitignore | 1 - data/epoch/consumer-rules.pro | 0 data/epoch/src/main/AndroidManifest.xml | 22 ------ .../unitto/data/epoch/EpochDateConverter.kt | 50 ------------- .../unitto/data/epoch/DateToEpochTest.kt | 60 ---------------- .../unitto/data/epoch/EpochToDateTest.kt | 72 ------------------- 6 files changed, 205 deletions(-) delete mode 100644 data/epoch/.gitignore delete mode 100644 data/epoch/consumer-rules.pro delete mode 100644 data/epoch/src/main/AndroidManifest.xml delete mode 100644 data/epoch/src/main/java/com/sadellie/unitto/data/epoch/EpochDateConverter.kt delete mode 100644 data/epoch/src/test/java/com/sadellie/unitto/data/epoch/DateToEpochTest.kt delete mode 100644 data/epoch/src/test/java/com/sadellie/unitto/data/epoch/EpochToDateTest.kt diff --git a/data/epoch/.gitignore b/data/epoch/.gitignore deleted file mode 100644 index 42afabfd..00000000 --- a/data/epoch/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/data/epoch/consumer-rules.pro b/data/epoch/consumer-rules.pro deleted file mode 100644 index e69de29b..00000000 diff --git a/data/epoch/src/main/AndroidManifest.xml b/data/epoch/src/main/AndroidManifest.xml deleted file mode 100644 index 7bdbce91..00000000 --- a/data/epoch/src/main/AndroidManifest.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/data/epoch/src/main/java/com/sadellie/unitto/data/epoch/EpochDateConverter.kt b/data/epoch/src/main/java/com/sadellie/unitto/data/epoch/EpochDateConverter.kt deleted file mode 100644 index d4957eb2..00000000 --- a/data/epoch/src/main/java/com/sadellie/unitto/data/epoch/EpochDateConverter.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Unitto is a unit converter for Android - * Copyright (c) 2023 Elshan Agaev - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sadellie.unitto.data.epoch - -import java.time.LocalDateTime -import java.time.ZoneOffset -import java.time.format.DateTimeFormatter -import java.time.format.DateTimeParseException - -object EpochDateConverter { - private val pattern by lazy { - DateTimeFormatter.ofPattern("HHmmssddMMyyyy") - } - - fun convertDateToUnix(date: String): String { - return try { - // Here we add some zeros, so that input is 14 symbols long - LocalDateTime - .parse(date.padEnd(14, '0'), pattern) - .toEpochSecond(ZoneOffset.UTC) - } catch (e: DateTimeParseException) { - 0 - }.toString() - } - - fun convertUnixToDate(unix: String): String { - val unixLong = unix.toLong().takeIf { it <= 253402300559L } - ?: throw IllegalArgumentException("Max unix is 253402300559") - - return LocalDateTime - .ofEpochSecond(unixLong, 0, ZoneOffset.UTC) - .format(pattern) - } -} \ No newline at end of file diff --git a/data/epoch/src/test/java/com/sadellie/unitto/data/epoch/DateToEpochTest.kt b/data/epoch/src/test/java/com/sadellie/unitto/data/epoch/DateToEpochTest.kt deleted file mode 100644 index 5a4ee4f7..00000000 --- a/data/epoch/src/test/java/com/sadellie/unitto/data/epoch/DateToEpochTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Unitto is a unit converter for Android - * Copyright (c) 2023 Elshan Agaev - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sadellie.unitto.data.epoch - -import org.junit.Assert.assertEquals -import org.junit.Test - -class DateToEpochTest { - - @Test - fun `00h0m00s 00 00 0000`() { - convertDateToUnixTest("00:00:00 00.00.0000", "0") - } - - @Test - fun `00h00m00s 01 01 0001`() { - convertDateToUnixTest("00:00:00 01.01.0001", "-62135596800") - } - - @Test - fun `00h00m00s 01 01 1970`() { - convertDateToUnixTest("00:00:00 01.01.1970", "0") - } - - @Test - fun `23h55m59s 31 12 9999`() { - convertDateToUnixTest("23:55:59 31.12.9999", "253402300559") - } - - @Test - fun `99h99m99s 99 99 9999`() { - convertDateToUnixTest("99:99:99 99.99.9999", "0") - } - - private fun convertDateToUnixTest(inputDate: String, expectedUnix: String) { - // Date input comes "fancy" - val cleanInputDate = inputDate.filter{ it.isDigit() } - assertEquals( - "Couldn't convert $inputDate ($cleanInputDate) into unix", - expectedUnix, - EpochDateConverter.convertDateToUnix(cleanInputDate) - ) - } -} diff --git a/data/epoch/src/test/java/com/sadellie/unitto/data/epoch/EpochToDateTest.kt b/data/epoch/src/test/java/com/sadellie/unitto/data/epoch/EpochToDateTest.kt deleted file mode 100644 index 12e16a68..00000000 --- a/data/epoch/src/test/java/com/sadellie/unitto/data/epoch/EpochToDateTest.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Unitto is a unit converter for Android - * Copyright (c) 2023 Elshan Agaev - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.sadellie.unitto.data.epoch - -import org.junit.Assert.assertEquals -import org.junit.Assert.assertThrows -import org.junit.Test - -class EpochToDateTest { - - @Test - fun `0`() { - convertUnixToDate("0", "00:00:00 01.01.1970") - } - - @Test - fun `00000000000000 max input length`() { - convertUnixToDate("00000000000000", "00:00:00 01.01.1970") - } - - @Test - fun `253402300559 max possible date`() { - convertUnixToDate("253402300559", "23:55:59 31.12.9999") - } - - @Test - fun `2534023005599999 input longe than allowed`() { - convertUnixToDate("2534023005599999", "23:55:59 31.12.9999", IllegalArgumentException()) - } - - @Test - fun `99999999999999 max possible unix with max length`() { - convertUnixToDate("99999999999999", "23:55:59 31.12.9999", IllegalArgumentException()) - } - - private fun convertUnixToDate(inputUnix: String, expectedDate: String, throwable: Throwable? = null) { - // Date input comes "fancy" - val cleanExpectedDate = expectedDate.filter{ it.isDigit() } - - // Will throw - if (throwable != null) { - assertThrows( - "Failed to throw ${throwable.javaClass} when converting $inputUnix into $expectedDate ($cleanExpectedDate)", - throwable.javaClass - ) { EpochDateConverter.convertUnixToDate(inputUnix) } - return - } - - // Should actually convert - assertEquals( - "Couldn't convert $inputUnix into $expectedDate ($cleanExpectedDate)", - cleanExpectedDate, - EpochDateConverter.convertUnixToDate(inputUnix) - ) - } -}