[BAEL-19059] - Move new articles to java-dates-operations module

This commit is contained in:
catalin-burcea
2019-12-07 18:12:55 +02:00
parent c1721cfaf7
commit 35711d3639
10 changed files with 21 additions and 21 deletions

View File

@@ -1,3 +1,8 @@
## Core Date Operations
This module contains articles about date operations in Java.
### Relevant Articles:
- [Get the Current Date Prior to Java 8](https://www.baeldung.com/java-get-the-current-date-legacy)
- [Skipping Weekends While Adding Days to LocalDate in Java 8](https://www.baeldung.com/java-localdate-add-days-skip-weekends)
- [Checking If Two Java Dates Are on the Same Day](https://www.baeldung.com/java-check-two-dates-on-same-day)
- [Converting Java Date to OffsetDateTime](https://www.baeldung.com/java-convert-date-to-offsetdatetime)

View File

@@ -5,6 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-date-operations</artifactId>
<version>${project.parent.version}</version>
<name>core-java-date-operations</name>
<packaging>jar</packaging>
<parent>

View File

@@ -0,0 +1,19 @@
package com.baeldung.offsetdatetime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Date;
public class ConvertToOffsetDateTime {
public static OffsetDateTime convert(Date date) {
return date.toInstant()
.atOffset(ZoneOffset.UTC);
}
public static OffsetDateTime convert(Date date, int hour, int minute) {
return date.toInstant()
.atOffset(ZoneOffset.ofHoursMinutes(hour, minute));
}
}

View File

@@ -1,13 +1,13 @@
package com.baeldung.date.comparison;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class DateComparisonUtilsUnitTest {

View File

@@ -1,15 +1,12 @@
package com.baeldung.datetime;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.baeldung.datetime.CalendarUtils;
import com.baeldung.datetime.DateUtils;
import java.text.ParseException;
import java.util.Date;
import static org.junit.Assert.assertEquals;
public class CalendarUtilsUnitTest {
@Test

View File

@@ -1,14 +1,12 @@
package com.baeldung.datetime;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.baeldung.datetime.DateUtils;
import java.text.ParseException;
import java.util.Date;
import static org.junit.Assert.assertEquals;
public class DateUtilsUnitTest {
@Test

View File

@@ -0,0 +1,29 @@
package com.baeldung.offsetdatetime;
import org.junit.Test;
import java.time.OffsetDateTime;
import java.util.Date;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ConvertToOffsetDateTimeUnitTest {
@Test
public void whenDateIsNotNull_thenConvertToOffsetDateTime() {
Date date = new Date();
assertTrue(ConvertToOffsetDateTime.convert(date) instanceof OffsetDateTime);
}
@Test
public void givenDate_whenHasOffset_thenConvertWithOffset() {
Date date = new Date();
date.setHours(6);
date.setMinutes(30);
OffsetDateTime odt = ConvertToOffsetDateTime.convert(date, 3, 30);
assertEquals(10, odt.getHour());
assertEquals(0, odt.getMinute());
}
}

View File

@@ -1,7 +1,8 @@
package com.baeldung.datetime;
package com.baeldung.skipweekends;
import static org.junit.Assert.assertEquals;
import com.baeldung.skipweekends.AddSubtractDaysSkippingWeekendsUtils;
import org.junit.Test;
import java.time.LocalDate;