mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-18 16:25:27 +02:00
remove unused epoch converter files
This commit is contained in:
parent
e530cdd7b0
commit
77762fca0f
1
data/epoch/.gitignore
vendored
1
data/epoch/.gitignore
vendored
@ -1 +0,0 @@
|
||||
/build
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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 <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<manifest>
|
||||
|
||||
</manifest>
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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)
|
||||
)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user