Skip to content

Commit

Permalink
(#39) Simplify new Date construction
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Dec 12, 2023
1 parent bcdc527 commit 17ed899
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
31 changes: 31 additions & 0 deletions src/main/java/com/github/fabriciofx/cactoos/pdf/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package com.github.fabriciofx.cactoos.pdf;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import org.cactoos.Text;
Expand All @@ -46,6 +48,35 @@ public Date() {
this(ZonedDateTime.now());
}

/**
* Ctor.
*
* @param year Year
* @param month Month
* @param day Day
* @param hour Hour
* @param minute Minute
* @param second Seconde
* @param zone Zone ID
* @checkstyle ParameterNumberCheck (15 lines)
*/
public Date(
final int year,
final int month,
final int day,
final int hour,
final int minute,
final int second,
final String zone
) {
this(
ZonedDateTime.of(
LocalDateTime.of(year, month, day, hour, minute, second),
ZoneId.of(zone)
)
);
}

/**
* Ctor.
*
Expand Down
10 changes: 1 addition & 9 deletions src/test/java/com/github/fabriciofx/cactoos/pdf/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
*/
package com.github.fabriciofx.cactoos.pdf;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.IsText;
Expand All @@ -40,12 +37,7 @@ final class DateTest {
void show() throws Exception {
new Assertion<>(
"Must represent a PDF date",
new Date(
ZonedDateTime.of(
LocalDateTime.of(2023, 12, 11, 20, 11, 32),
ZoneId.of("Etc/GMT-3")
)
),
new Date(2023, 12, 11, 20, 11, 32, "Etc/GMT-3"),
new IsText("D:20231211201132+03'00'")
).affirm();
}
Expand Down
45 changes: 6 additions & 39 deletions src/test/java/com/github/fabriciofx/cactoos/pdf/DocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
import com.github.fabriciofx.cactoos.pdf.resource.Resources;
import java.io.File;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;
import org.cactoos.text.Joined;
Expand All @@ -60,12 +57,7 @@ final class DocumentTest {
@Test
void buildDocument() throws Exception {
final Count count = new ObjectCount();
final Date date = new Date(
ZonedDateTime.of(
LocalDateTime.of(2023, 12, 11, 20, 11, 32),
ZoneId.of("Etc/GMT-3")
)
);
final Date date = new Date(2023, 12, 11, 20, 11, 32, "Etc/GMT-3");
new Assertion<>(
"Must represent a PDF document",
new TextOf(
Expand Down Expand Up @@ -134,12 +126,7 @@ void buildDocument() throws Exception {
@Test
void buildMultiTextDocument() throws Exception {
final Count count = new ObjectCount();
final Date date = new Date(
ZonedDateTime.of(
LocalDateTime.of(2023, 12, 11, 20, 11, 32),
ZoneId.of("Etc/GMT-3")
)
);
final Date date = new Date(2023, 12, 11, 20, 11, 32, "Etc/GMT-3");
new Assertion<>(
"Must represent a PDF document",
new TextOf(
Expand Down Expand Up @@ -242,12 +229,7 @@ void buildMultiTextDocument() throws Exception {
@Test
void buildTwoPagesDocument() throws Exception {
final Count count = new ObjectCount();
final Date date = new Date(
ZonedDateTime.of(
LocalDateTime.of(2023, 12, 11, 20, 11, 32),
ZoneId.of("Etc/GMT-3")
)
);
final Date date = new Date(2023, 12, 11, 20, 11, 32, "Etc/GMT-3");
new Assertion<>(
"Must represent a two pages PDF document",
new TextOf(
Expand Down Expand Up @@ -338,12 +320,7 @@ void buildTwoPagesDocument() throws Exception {
void buildFile() throws Exception {
final File file = new File("HelloWorld.pdf");
final Count count = new ObjectCount();
final Date date = new Date(
ZonedDateTime.of(
LocalDateTime.of(2023, 12, 11, 20, 11, 32),
ZoneId.of("Etc/GMT-3")
)
);
final Date date = new Date(2023, 12, 11, 20, 11, 32, "Etc/GMT-3");
Files.write(
file.toPath(),
new Document(
Expand Down Expand Up @@ -415,12 +392,7 @@ void buildFile() throws Exception {
void buildMultiFile() throws Exception {
final File file = new File("HelloWorld.pdf");
final Count count = new ObjectCount();
final Date date = new Date(
ZonedDateTime.of(
LocalDateTime.of(2023, 12, 11, 20, 11, 32),
ZoneId.of("Etc/GMT-3")
)
);
final Date date = new Date(2023, 12, 11, 20, 11, 32, "Etc/GMT-3");
Files.write(
file.toPath(),
new Document(
Expand Down Expand Up @@ -493,12 +465,7 @@ void buildMultiFile() throws Exception {
void buildEncodedFile() throws Exception {
final File file = new File("HelloWorld.pdf");
final Count count = new ObjectCount();
final Date date = new Date(
ZonedDateTime.of(
LocalDateTime.of(2023, 12, 11, 20, 11, 32),
ZoneId.of("Etc/GMT-3")
)
);
final Date date = new Date(2023, 12, 11, 20, 11, 32, "Etc/GMT-3");
Files.write(
file.toPath(),
new Document(
Expand Down

0 comments on commit 17ed899

Please sign in to comment.