| @ -0,0 +1,27 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <classpath> | |||||
| <classpathentry kind="src" output="target/classes" path="src/main/java"> | |||||
| <attributes> | |||||
| <attribute name="optional" value="true"/> | |||||
| <attribute name="maven.pomderived" value="true"/> | |||||
| </attributes> | |||||
| </classpathentry> | |||||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> | |||||
| <attributes> | |||||
| <attribute name="maven.pomderived" value="true"/> | |||||
| </attributes> | |||||
| </classpathentry> | |||||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||||
| <attributes> | |||||
| <attribute name="maven.pomderived" value="true"/> | |||||
| </attributes> | |||||
| </classpathentry> | |||||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||||
| <attributes> | |||||
| <attribute name="optional" value="true"/> | |||||
| <attribute name="maven.pomderived" value="true"/> | |||||
| <attribute name="test" value="true"/> | |||||
| </attributes> | |||||
| </classpathentry> | |||||
| <classpathentry kind="output" path="target/classes"/> | |||||
| </classpath> | |||||
| @ -0,0 +1,4 @@ | |||||
| /.metadata/ | |||||
| /.recommenders/ | |||||
| /RemoteSystemsTempFiles/ | |||||
| .settings/ | |||||
| @ -0,0 +1,23 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <projectDescription> | |||||
| <name>JDate</name> | |||||
| <comment></comment> | |||||
| <projects> | |||||
| </projects> | |||||
| <buildSpec> | |||||
| <buildCommand> | |||||
| <name>org.eclipse.jdt.core.javabuilder</name> | |||||
| <arguments> | |||||
| </arguments> | |||||
| </buildCommand> | |||||
| <buildCommand> | |||||
| <name>org.eclipse.m2e.core.maven2Builder</name> | |||||
| <arguments> | |||||
| </arguments> | |||||
| </buildCommand> | |||||
| </buildSpec> | |||||
| <natures> | |||||
| <nature>org.eclipse.jdt.core.javanature</nature> | |||||
| <nature>org.eclipse.m2e.core.maven2Nature</nature> | |||||
| </natures> | |||||
| </projectDescription> | |||||
| @ -0,0 +1,32 @@ | |||||
| # JDate | |||||
| Static methods: | |||||
| defaultDateFormat = "dd-MM-yyyy" | |||||
| defaultTimeFormat = "HH:mm:ss" | |||||
| void setDefaultDateFormat(String format) | |||||
| void setDefaultTimeFormat(String format) | |||||
| Date getDate(String date) | |||||
| Date getDate(String date, String time) | |||||
| String getDate(Date date) | |||||
| String getTime(Date date) | |||||
| Date setDate(Date date, String set) | |||||
| Date setTime(Date date, String set) | |||||
| int getDay(Date date) | |||||
| int getMonth(Date date) // 0-January, 1-February, ... 11-December | |||||
| int getCorrectMonth(Date date) // human-like month numeration (1-January, 2-February, ... 12-December) | |||||
| int getYear(Date date) | |||||
| Date incDay(Date date, int days) | |||||
| Date incMonth(Date date, int months) | |||||
| Date incYear(Date date, int years) | |||||
| Date nullTime(Date date) | |||||
| long getDifferenceDays(Date from, Date to) | |||||
| int getDifferenceYears(Date from, Date to) | |||||
| @ -0,0 +1,38 @@ | |||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | |||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||||
| <modelVersion>4.0.0</modelVersion> | |||||
| <groupId>com.gmail.develop.jcant</groupId> | |||||
| <artifactId>JDate</artifactId> | |||||
| <version>1.6</version> | |||||
| <packaging>jar</packaging> | |||||
| <name>JDate</name> | |||||
| <description>Date/Time routines</description> | |||||
| <url>https://github.com/jcant/JDate.git</url> | |||||
| <properties> | |||||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||||
| <java.version>1.8</java.version> | |||||
| </properties> | |||||
| <dependencies> | |||||
| </dependencies> | |||||
| <!-- | |||||
| <build> | |||||
| <plugins> | |||||
| <plugin> | |||||
| <groupId>org.apache.maven.plugins</groupId> | |||||
| <artifactId>maven-compiler-plugin</artifactId> | |||||
| <version>3.7.0</version> | |||||
| <configuration> | |||||
| <source>1.8</source> | |||||
| <target>1.8</target> | |||||
| </configuration> | |||||
| </plugin> | |||||
| </plugins> | |||||
| </build> | |||||
| --> | |||||
| </project> | |||||
| @ -0,0 +1,170 @@ | |||||
| package com.gmail.develop.jcant; | |||||
| import java.text.ParseException; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.Calendar; | |||||
| import java.util.Date; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| public class JDate { | |||||
| private static String defaultDateFormat = "dd-MM-yyyy"; | |||||
| private static String defaultTimeFormat = "HH:mm:ss"; | |||||
| public static void setDefaultDateFormat(String format) { | |||||
| defaultDateFormat = format; | |||||
| } | |||||
| public static void setDefaultTimeFormat(String format) { | |||||
| defaultTimeFormat = format; | |||||
| } | |||||
| // --- static --- | |||||
| public static Date getDate(String date) { | |||||
| SimpleDateFormat sdf = new SimpleDateFormat(defaultDateFormat); | |||||
| Date result = null; | |||||
| try { | |||||
| result = sdf.parse(date); | |||||
| } catch (ParseException e) { | |||||
| System.err.println("Error getting quick date!"); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| public static Date getDate(String date, String time){ | |||||
| return setTime(getDate(date), time); | |||||
| } | |||||
| public static String getDate(Date date) { | |||||
| SimpleDateFormat sdf = new SimpleDateFormat(defaultDateFormat); | |||||
| String result = sdf.format(date); | |||||
| return result; | |||||
| } | |||||
| public static Date setDate(Date date, String set){ | |||||
| if (date == null) { | |||||
| throw new IllegalArgumentException(); | |||||
| } | |||||
| Calendar our = Calendar.getInstance(); | |||||
| Calendar setter = Calendar.getInstance(); | |||||
| our.setTime(date); | |||||
| SimpleDateFormat sdf = new SimpleDateFormat(defaultDateFormat); | |||||
| try { | |||||
| setter.setTime(sdf.parse(set)); | |||||
| } catch (ParseException e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| our.set(setter.get(Calendar.YEAR), setter.get(Calendar.MONTH), setter.get(Calendar.DAY_OF_MONTH)); | |||||
| return our.getTime(); | |||||
| } | |||||
| public static String getTime(Date date) { | |||||
| SimpleDateFormat sdf = new SimpleDateFormat(defaultTimeFormat); | |||||
| String result = sdf.format(date); | |||||
| return result; | |||||
| } | |||||
| public static Date setTime(Date date, String set){ | |||||
| if (date == null) { | |||||
| throw new IllegalArgumentException(); | |||||
| } | |||||
| Calendar our = Calendar.getInstance(); | |||||
| Calendar setter = Calendar.getInstance(); | |||||
| our.setTime(date); | |||||
| SimpleDateFormat sdf = new SimpleDateFormat(defaultTimeFormat); | |||||
| try { | |||||
| setter.setTime(sdf.parse(set)); | |||||
| } catch (ParseException e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| 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); | |||||
| return our.getTime(); | |||||
| } | |||||
| public static Date nullTime(Date date){ | |||||
| if (date == null) { | |||||
| throw new IllegalArgumentException(); | |||||
| } | |||||
| Calendar our = Calendar.getInstance(); | |||||
| our.setTime(date); | |||||
| our.set(Calendar.HOUR_OF_DAY, 0); | |||||
| our.set(Calendar.MINUTE, 0); | |||||
| our.set(Calendar.SECOND, 0); | |||||
| our.set(Calendar.MILLISECOND, 0); | |||||
| return our.getTime(); | |||||
| } | |||||
| public static long getDifferenceDays(Date from, Date to) { | |||||
| long msDiff = to.getTime() - from.getTime(); | |||||
| long diff = TimeUnit.DAYS.convert(msDiff, TimeUnit.MILLISECONDS); | |||||
| return diff; | |||||
| } | |||||
| public static int getDifferenceYears(Date from, Date to) { | |||||
| Calendar dayFrom = Calendar.getInstance(); | |||||
| dayFrom.setTime(from); | |||||
| Calendar dayTo = Calendar.getInstance(); | |||||
| dayTo.setTime(to); | |||||
| int diff = dayTo.get(Calendar.YEAR) - dayFrom.get(Calendar.YEAR); | |||||
| dayTo.set(Calendar.YEAR, dayFrom.get(Calendar.YEAR)); | |||||
| if (dayFrom.compareTo(dayTo) >= 0) { | |||||
| diff--; | |||||
| } | |||||
| return diff; | |||||
| } | |||||
| public static int getDay(Date date) { | |||||
| Calendar day = Calendar.getInstance(); | |||||
| day.setTime(date); | |||||
| return day.get(Calendar.DAY_OF_MONTH); | |||||
| } | |||||
| // 0-January, 1-February, ... 11-December | |||||
| public static int getMonth(Date date) { | |||||
| Calendar day = Calendar.getInstance(); | |||||
| day.setTime(date); | |||||
| return day.get(Calendar.MONTH); | |||||
| } | |||||
| // human-like month numeration | |||||
| public static int getCorrectMonth(Date date) { | |||||
| return getMonth(date) + 1; | |||||
| } | |||||
| public static int getYear(Date date) { | |||||
| Calendar day = Calendar.getInstance(); | |||||
| day.setTime(date); | |||||
| return day.get(Calendar.YEAR); | |||||
| } | |||||
| public static Date incDay(Date date, int days) { | |||||
| Calendar day = Calendar.getInstance(); | |||||
| day.setTime(date); | |||||
| day.add(Calendar.DAY_OF_MONTH, days); | |||||
| return day.getTime(); | |||||
| } | |||||
| public static Date incMonth(Date date, int months) { | |||||
| Calendar day = Calendar.getInstance(); | |||||
| day.setTime(date); | |||||
| day.add(Calendar.MONTH, months); | |||||
| return day.getTime(); | |||||
| } | |||||
| public static Date incYear(Date date, int years) { | |||||
| Calendar day = Calendar.getInstance(); | |||||
| day.setTime(date); | |||||
| day.add(Calendar.YEAR, years); | |||||
| return day.getTime(); | |||||
| } | |||||
| //this is comment | |||||
| } | |||||
| @ -0,0 +1,5 @@ | |||||
| Manifest-Version: 1.0 | |||||
| Built-By: jcant | |||||
| Build-Jdk: 11.0.4 | |||||
| Created-By: Maven Integration for Eclipse | |||||
| @ -0,0 +1,7 @@ | |||||
| #Generated by Maven Integration for Eclipse | |||||
| #Sun Aug 18 20:54:17 EEST 2019 | |||||
| m2e.projectLocation=/home/jcant/LuckyProject/Helpers/JDate | |||||
| m2e.projectName=JDate | |||||
| groupId=com.gmail.develop.jcant | |||||
| artifactId=JDate | |||||
| version=1.6 | |||||
| @ -0,0 +1,38 @@ | |||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | |||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||||
| <modelVersion>4.0.0</modelVersion> | |||||
| <groupId>com.gmail.develop.jcant</groupId> | |||||
| <artifactId>JDate</artifactId> | |||||
| <version>1.6</version> | |||||
| <packaging>jar</packaging> | |||||
| <name>JDate</name> | |||||
| <description>Date/Time routines</description> | |||||
| <url>https://github.com/jcant/JDate.git</url> | |||||
| <properties> | |||||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||||
| <java.version>1.8</java.version> | |||||
| </properties> | |||||
| <dependencies> | |||||
| </dependencies> | |||||
| <!-- | |||||
| <build> | |||||
| <plugins> | |||||
| <plugin> | |||||
| <groupId>org.apache.maven.plugins</groupId> | |||||
| <artifactId>maven-compiler-plugin</artifactId> | |||||
| <version>3.7.0</version> | |||||
| <configuration> | |||||
| <source>1.8</source> | |||||
| <target>1.8</target> | |||||
| </configuration> | |||||
| </plugin> | |||||
| </plugins> | |||||
| </build> | |||||
| --> | |||||
| </project> | |||||
| @ -0,0 +1,5 @@ | |||||
| #Generated by Maven | |||||
| #Sun Aug 18 20:50:28 EEST 2019 | |||||
| groupId=com.gmail.develop.jcant | |||||
| artifactId=JDate | |||||
| version=1.6 | |||||
| @ -0,0 +1 @@ | |||||
| /home/jcant/LuckyProject/Helpers/JDate/src/main/java/com/gmail/develop/jcant/JDate.java | |||||