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/.gitignore b/.gitignore index e58e14f..3ed6619 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ /.recommenders/ /RemoteSystemsTempFiles/ .settings/ -target/ -/target/ \ No newline at end of file +target/*.* +/target/ 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..d581589 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(); } @@ -223,7 +223,10 @@ public class JDate { public static int getWeekDay(Date date) { Calendar day = Calendar.getInstance(); day.setTime(date); - return day.get(Calendar.DAY_OF_WEEK); + int num = day.get(Calendar.DAY_OF_WEEK); + num--; + if (num < 1) num = 7; + return num; } public static int getDay(Date date) { 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..41f8df5 --- /dev/null +++ b/src/test/java/com/gmail/develop/jcant/JDateTest.java @@ -0,0 +1,205 @@ +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() { + Date date1 = new Date(1592204400000l); //15-06-2020 10:00:00 + Date date2 = new Date(1670659200000l); //10-12-2022 10:00:00 + Date date3 = new Date(1577692800000l); //30-12-2019 10:00:00 + Date date4 = new Date(1551600000000l); //03-03-2019 10:00:00 + boolean t1 = JDate.getDifferenceYears(date1, date2) == 2; + boolean t2 = JDate.getDifferenceYears(date1, date3) == -1; + boolean t3 = JDate.getDifferenceYears(date1, date4) == -2; + assertTrue(t1 && t2 && t3); + } + + @Test + public void testGetWeekDay() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 - SUNDAY + assertEquals(JDate.getWeekDay(date), 7); + } + + @Test + public void testGetDay() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getDay(date), 17); + } + + @Test + public void testGetMonth() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getMonth(date), 0); + } + + @Test + public void testGetCorrectMonth() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getCorrectMonth(date), 1); + } + + @Test + public void testGetYear() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.getYear(date), 2021); + } + + @Test + public void testIncDay() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.incDay(date, 2).getTime(), 1611043200000l); //19-01-2021 10:00:00 + } + + @Test + public void testIncMonth() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.incMonth(date, 2).getTime(), 1615968000000l); //17-03-2021 10:00:00 + } + + @Test + public void testIncYear() { + Date date = new Date(1610870400000l); //17-01-2021 10:00:00 + assertEquals(JDate.incYear(date, -2).getTime(), 1547712000000l); //17-03-2021 10:00:00 + } + +} diff --git a/target/classes/com/gmail/develop/jcant/JDate.class b/target/classes/com/gmail/develop/jcant/JDate.class deleted file mode 100644 index d3640da..0000000 Binary files a/target/classes/com/gmail/develop/jcant/JDate.class and /dev/null differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties deleted file mode 100644 index b336468..0000000 --- a/target/maven-archiver/pom.properties +++ /dev/null @@ -1,5 +0,0 @@ -#Generated by Maven -#Mon Oct 28 20:17:45 EET 2019 -groupId=com.gmail.develop.jcant -artifactId=JDate -version=1.9 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 deleted file mode 100644 index 093e2ed..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index e6f3170..0000000 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1 +0,0 @@ -/home/jcadm/LuckyProject/Helpers/JDate/src/main/java/com/gmail/develop/jcant/JDate.java