Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/runConfigurations/time_machine__build___warning_mode_all_.xml
#	.idea/runConfigurations/time_machine__clean_publishMavenJavaPublicationToMavenLocal_publish_.xml
#	.idea/runConfigurations/time_machine__tagRelease_.xml
#	CHANGELOG.md
#	gradle.properties
#	gradle/dependencies.gradle
#	gradle/wrapper/gradle-wrapper.properties
#	src/main/java/module-info.java
  • Loading branch information
astrapi69 committed Aug 31, 2023
2 parents 8b4a991 + 6b3d917 commit 547ed86
Show file tree
Hide file tree
Showing 32 changed files with 829 additions and 330 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,35 @@ CHANGED:
- update of test dependency 'com.github.meanbeanlib:meanbean' to new version 3.0.0-M9
- update of test dependency junit-jupiter to new version 5.10.0

Version 2.5
-------------

ADDED:

- new test class for Period

CHANGED:

- removed deprecated methods from all classes
- increase of code coverage

Version 2.4
-------------

ADDED:

- new class DateExtensions for convert Date objects to the new java.time.* classes
- new class XMLGregorianCalendarExtensions for convert Date objects to the new java.time.* classes

CHANGED:

- update of gradle to new version 8.0.1
- update of gradle-plugin dependency 'com.diffplug.spotless:spotless-plugin-gradle' in version 6.15.0
- update of com.github.ben-manes.versions.gradle.plugin to new version 0.46.0
- update of test dependency vintage-time to new version 5.4
- update of test dependency meanbean to new version 3.0.0-M9
- update of test dependency junit-jupiter (junit 5) to new version 5.9.2

Version 2.3
-------------

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Than you can add the dependency to your dependencies:
<properties>
...
<!-- TIME-MACHINE version -->
<time-machine.version>2.3</time-machine.version>
<time-machine.version>2.5</time-machine.version>
...
</properties>
...
Expand All @@ -81,15 +81,15 @@ project `build.gradle` if you want to import the core functionality of time-mach
define version in file gradle.properties

```
timeMachineVersion=2.3
timeMachineVersion=2.5
```

or in build.gradle ext area

```
ext {
...
timeMachineVersion = "2.3"
timeMachineVersion = "2.5"
...
}
```
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spotlessGradlePluginVersion=6.21.0
##############################
# test dependencies versions #
##############################
vintageTimeVersion=5.2
vintageTimeVersion=5.4
meanbeanVersion=3.0.0-M9
junitJupiterVersion=5.10.0
##########################
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
testImplementation("de.alpharogroup:vintage-time:$vintageTimeVersion")
testImplementation("io.github.astrapi69:vintage-time:$vintageTimeVersion")
testImplementation("com.github.meanbeanlib:meanbean:$meanbeanVersion")
testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
Expand Down
1 change: 1 addition & 0 deletions gradle/testing.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test {
mustRunAfter(jar)
useJUnitPlatform()
}

Expand Down
136 changes: 136 additions & 0 deletions src/main/java/io/github/astrapi69/time/convert/DateExtensions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* The MIT License
* <p>
* Copyright (C) 2015 Asterios Raptis
* <p>
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* <p>
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.github.astrapi69.time.convert;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Objects;

/**
* The class {@link DateExtensions} provides methods for convert {@link Date} objects
*/
public class DateExtensions
{

/**
* Converts the given {@link Date} with the given {@link ZoneId} to a {@link LocalDate} object
*
* @param date
* the date
* @param zone
* the zone
* @return The {@link LocalDate} object
*/
public static LocalDate toLocalDate(Date date, ZoneId zone)
{
return date.toInstant().atZone(zone).toLocalDate();
}

/**
* Converts the given {@link Date} with the given {@link ZoneId} to a {@link LocalDateTime}
* object
*
* @param date
* the date
* @param zone
* the zone
* @return The {@link LocalDateTime} object
*/
public static LocalDateTime toLocalDateTime(Date date, ZoneId zone)
{
return date.toInstant().atZone(zone).toLocalDateTime();
}

/**
* Converts the given {@link Date} with the given {@link ZoneId} to a {@link OffsetDateTime}
* object
*
* @param date
* the date
* @param zone
* the zone
* @return The {@link OffsetDateTime} object
*/
public static OffsetDateTime toOffsetDateTime(Date date, ZoneId zone)
{
Objects.requireNonNull(date);
Objects.requireNonNull(zone);
return toOffsetDateTime(date, zone.getRules().getOffset(date.toInstant()));
}

/**
* Converts the given {@link Date} with the given {@link ZoneOffset} to a {@link OffsetDateTime}
* object
*
* @param date
* the date
* @param zoneOffset
* the zone offset
* @return The {@link OffsetDateTime} object
*/
public static OffsetDateTime toOffsetDateTime(Date date, ZoneOffset zoneOffset)
{
Objects.requireNonNull(date);
Objects.requireNonNull(zoneOffset);
return date.toInstant().atOffset(zoneOffset);
}

/**
* Converts the given {@link Date} with the given {@link ZoneId} to a {@link ZonedDateTime}
* object
*
* @param date
* the date
* @param zone
* the zone
* @return The {@link ZonedDateTime} object
*/
public static ZonedDateTime toZonedDateTime(Date date, ZoneId zone)
{
return OffsetDateTimeExtensions
.toZonedDateTime(DateExtensions.toOffsetDateTime(date, zone));
}

/**
* Converts the given {@link Instant} with the given {@link ZoneId} to a {@link ZoneOffset} *
* object
*
* @param instant
* the instant
* @param zoneId
* the zone
* @return the {@link ZoneOffset} object
*/
public static ZoneOffset toZoneOffset(Instant instant, ZoneId zoneId)
{
return zoneId.getRules().getOffset(instant);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* The MIT License
* <p>
*
* Copyright (C) 2015 Asterios Raptis
* <p>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* <p>
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* <p>
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -24,15 +24,15 @@
*/
package io.github.astrapi69.time.convert;

import io.github.astrapi69.time.enumtype.DatePattern;
import io.github.astrapi69.time.formatter.DateTimeFormatterFactory;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.Locale;

import io.github.astrapi69.time.enumtype.DatePattern;
import io.github.astrapi69.time.formatter.DateTimeFormatterFactory;

/**
* The class {@link LocalDateExtensions} provides methods for convert {@link LocalDate} objects
*/
Expand All @@ -51,20 +51,6 @@ public static Timestamp toTimestamp(LocalDate localDate)
return Timestamp.valueOf(localDate.atStartOfDay());
}

/**
* Converts the given {@link Date} with the given {@link ZoneId} to a {@link LocalDate} object
*
* @param date
* the date
* @param zone
* the zone
* @return The {@link LocalDate} object
*/
public static LocalDate toLocalDate(Date date, ZoneId zone)
{
return date.toInstant().atZone(zone).toLocalDate();
}

/**
* Converts the given {@link LocalDate} to a {@link java.sql.Date} object
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* The MIT License
* <p>
*
* Copyright (C) 2015 Asterios Raptis
* <p>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* <p>
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* <p>
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -24,10 +24,13 @@
*/
package io.github.astrapi69.time.convert;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;

/**
* The class {@link LocalDateTimeExtensions} provides methods for convert {@link LocalDateTime}
Expand All @@ -37,18 +40,19 @@ public class LocalDateTimeExtensions
{

/**
* Converts the given {@link Date} with the given {@link ZoneId} to a {@link LocalDateTime}
* object
* Converts the given {@link LocalDateTime} to a {@link XMLGregorianCalendar} object
*
* @param date
* the date
* @param zone
* the zone
* @return The {@link LocalDateTime} object
* @param localDateTime
* the {@link LocalDateTime} object
* @return The {@link XMLGregorianCalendar} object
* @throws DatatypeConfigurationException
* is thrown if the implementation is not available or cannot be instantiated
*/
public static LocalDateTime toLocalDateTime(Date date, ZoneId zone)
public static XMLGregorianCalendar toXMLGregorianCalendar(LocalDateTime localDateTime)
throws DatatypeConfigurationException
{
return date.toInstant().atZone(zone).toLocalDateTime();
Objects.requireNonNull(localDateTime);
return DatatypeFactory.newInstance().newXMLGregorianCalendar(localDateTime.toString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* The MIT License
* <p>
*
* Copyright (C) 2015 Asterios Raptis
* <p>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* <p>
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* <p>
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down
Loading

0 comments on commit 547ed86

Please sign in to comment.