diff --git a/.classpath b/.classpath index e23a0f6..1ce4e9c 100644 --- a/.classpath +++ b/.classpath @@ -6,7 +6,7 @@ - + @@ -18,9 +18,9 @@ + - diff --git a/pom.xml b/pom.xml index 3981d99..0959cd6 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,13 @@ 1.6 + + + org.junit.jupiter + junit-jupiter-api + 5.7.0 + test + diff --git a/some_new_file.txt b/some_new_file.txt deleted file mode 100644 index 0fd933f..0000000 --- a/some_new_file.txt +++ /dev/null @@ -1 +0,0 @@ -asdf asdf asdf adsf adsf adsf afds adsf diff --git a/src/main/java/com/gmail/develop/jcant/JDate.java b/src/main/java/com/gmail/develop/jcant/JDate.java index 0e9e671..060ee61 100644 --- a/src/main/java/com/gmail/develop/jcant/JDate.java +++ b/src/main/java/com/gmail/develop/jcant/JDate.java @@ -121,7 +121,7 @@ public class JDate { our.set(Calendar.HOUR_OF_DAY, setter.get(Calendar.HOUR_OF_DAY)); our.set(Calendar.MINUTE, setter.get(Calendar.MINUTE)); - our.set(Calendar.SECOND, 0); + our.set(Calendar.SECOND, setter.get(Calendar.SECOND)); return our.getTime(); } diff --git a/src/test/java/com/gmail/develop/jcant/JDateTest.java b/src/test/java/com/gmail/develop/jcant/JDateTest.java new file mode 100644 index 0000000..6b4e40c --- /dev/null +++ b/src/test/java/com/gmail/develop/jcant/JDateTest.java @@ -0,0 +1,190 @@ +package com.gmail.develop.jcant; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Date; + +import org.junit.jupiter.api.Test; + +public class JDateTest { + + + + @Test + public void testSetDefaultDateFormat() { + JDate.setDefaultDateFormat("DD/MM/YYYY"); + assertEquals(JDate.getDefaultDateFormat(), "DD/MM/YYYY"); + JDate.setDefaultDateFormat("dd-MM-yyyy"); + } + + @Test + public void testGetDefaultDateFormat() { + JDate.setDefaultDateFormat("DD/MM/YYYY"); + assertEquals(JDate.getDefaultDateFormat(), "DD/MM/YYYY"); + JDate.setDefaultDateFormat("dd-MM-yyyy"); + } + + @Test + public void testSetDefaultTimeFormat() { + JDate.setDefaultTimeFormat("HH-MM-SS"); + assertEquals(JDate.getDefaultTimeFormat(), "HH-MM-SS"); + JDate.setDefaultTimeFormat("HH:mm:ss"); + } + + @Test + public void testGetDefaultTimeFormat() { + JDate.setDefaultTimeFormat("HH-MM-SS"); + assertEquals(JDate.getDefaultTimeFormat(), "HH-MM-SS"); + JDate.setDefaultTimeFormat("HH:mm:ss"); + } + + @Test + public void testCreateDate() { + //test creation '01-January-2021': + assertEquals(JDate.createDate(01, 00, 2021).getTime(), 1609452000000l); //01-01-2021 00:00:00 + } + + @Test + public void testGetDateString() { + assertEquals(JDate.getDate("05-05-2021").getTime(), 1620162000000l); //05-05-2021 00:00:00 + } + + @Test + public void testGetDateStringString() { + assertEquals(JDate.getDate("05-05-2021", "08:30:30").getTime(), 1620192630000l); //05-05-2021 08:30:30 + } + + @Test + public void testGetDateDate() { + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.getDate(date), "05-05-2021"); + } + + @Test + public void testSetDateDateString() { + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.setDate(date, "10-10-2022").getTime(), 1665379830000l); //10-10-2022 08:30:30 + } + + @Test + public void testSetDateDateIntIntInt() { + //test creation '10-October-2022': + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.setDate(date, 10, 9, 2022).getTime(), 1665379830000l); //10-10-2022 08:30:30 + } + + @Test + public void testGetTime() { + Date date = new Date(1620192630000l); //05-05-2021 08:30:30 + assertEquals(JDate.getTime(date), "08:30:30"); + } + + @Test + public void testSetTimeDateString() { + Date date = new Date(1665379830000l); //10-10-2022 08:30:30 + assertEquals(JDate.setTime(date, "12:48:11").getTime(), 1665395291000l); //10-10-2022 12:48:11 + } + + @Test + public void testSetTimeDateIntIntInt() { + Date date = new Date(1665379830000l); //10-10-2022 08:30:30 + assertEquals(JDate.setTime(date, 12, 48, 11).getTime(), 1665395291000l); //10-10-2022 12:48:11 + } + + @Test + public void testNullTime() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.nullTime(date).getTime(), 1665349200000l); //10-10-2022 00:00:00 + } + + @Test + public void testGetHours() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.getHours(date), 12); + } + + @Test + public void testGetMinutes() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.getMinutes(date), 48); + } + + @Test + public void testGetSeconds() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.getSeconds(date), 11); + } + + @Test + public void testIncHours() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.incHours(date, 3).getTime(), 1665406091000l); //10-10-2022 15:48:11 + } + + @Test + public void testIncMinutes() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.incMinutes(date, -10).getTime(), 1665394691000l); //10-10-2022 12:38:11 + } + + @Test + public void testIncSeconds() { + Date date = new Date(1665395291000l); //10-10-2022 12:48:11 + assertEquals(JDate.incSeconds(date, 20).getTime(), 1665395311000l); //10-10-2022 12:48:31 + } + + @Test + public void testGetDifferenceDays() { + Date date1 = new Date(1665395291000l); //10-10-2022 12:48:11 + Date date2 = new Date(1662185523000l); //03-09-2022 09:12:03 + Date date3 = new Date(1662200115000l); //03-09-2022 13:15:15 + + assertTrue((JDate.getDifferenceDays(date1, date2) == -37) && (JDate.getDifferenceDays(date3, date1) == 36)); + } + + @Test + public void testGetDifferenceYears() { + fail("Not yet implemented"); + } + + @Test + public void testGetWeekDay() { + fail("Not yet implemented"); + } + + @Test + public void testGetDay() { + fail("Not yet implemented"); + } + + @Test + public void testGetMonth() { + fail("Not yet implemented"); + } + + @Test + public void testGetCorrectMonth() { + fail("Not yet implemented"); + } + + @Test + public void testGetYear() { + fail("Not yet implemented"); + } + + @Test + public void testIncDay() { + fail("Not yet implemented"); + } + + @Test + public void testIncMonth() { + fail("Not yet implemented"); + } + + @Test + public void testIncYear() { + fail("Not yet implemented"); + } + +} diff --git a/target/classes/com/gmail/develop/jcant/JDate.class b/target/classes/com/gmail/develop/jcant/JDate.class index d3640da..c42e38f 100644 Binary files a/target/classes/com/gmail/develop/jcant/JDate.class and b/target/classes/com/gmail/develop/jcant/JDate.class differ diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 093e2ed..6bf119e 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1 +1 @@ -com/gmail/develop/jcant/JDate.class +com\gmail\develop\jcant\JDate.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index e6f3170..d118466 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1 +1 @@ -/home/jcadm/LuckyProject/Helpers/JDate/src/main/java/com/gmail/develop/jcant/JDate.java +D:\JC\Develop\Java\JDate\src\main\java\com\gmail\develop\jcant\JDate.java