From 9f6ff3a9cfd01fe7932550179bfe3bc900cc1e31 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 5 Feb 2020 18:52:42 +0100 Subject: [PATCH] Fixed damned year alignment. --- .../agirstatool/core/AgirStatoolUtils.java | 2 +- test/org/april/agirstatool/core/JugaTest.java | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/org/april/agirstatool/core/AgirStatoolUtils.java b/src/org/april/agirstatool/core/AgirStatoolUtils.java index caa04c6..8dde07d 100644 --- a/src/org/april/agirstatool/core/AgirStatoolUtils.java +++ b/src/org/april/agirstatool/core/AgirStatoolUtils.java @@ -577,7 +577,7 @@ public class AgirStatoolUtils } else { - result = source.format(DateTimeFormatter.ofPattern("yyyyww", Locale.FRANCE)); + result = source.format(DateTimeFormatter.ofPattern("YYYYww", Locale.FRANCE)); } // diff --git a/test/org/april/agirstatool/core/JugaTest.java b/test/org/april/agirstatool/core/JugaTest.java index 5b78269..f40ec25 100644 --- a/test/org/april/agirstatool/core/JugaTest.java +++ b/test/org/april/agirstatool/core/JugaTest.java @@ -18,10 +18,16 @@ */ package org.april.agirstatool.core; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.SignStyle; +import java.time.temporal.IsoFields; +import java.util.Locale; + import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.april.agirstatool.core.AgirStatoolException; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -45,6 +51,33 @@ public class JugaTest logger.debug("===== test done."); } + @Test + public void testWeek() throws Exception + { + // + logger.debug("===== test starting..."); + + System.out.println("==> " + LocalDate.now().getDayOfWeek()); + System.out.println("==> " + LocalDate.now().getDayOfWeek().getValue()); + System.out.println("==> " + AgirStatoolUtils.normaliseWeekDate(LocalDate.now())); + System.out.println("==> " + AgirStatoolUtils.toYearWeek(LocalDate.of(2019, 12, 30))); + + System.out.println(LocalDate.of(2019, 12, 30).format(DateTimeFormatter.ofPattern("yyyyww", Locale.FRENCH))); + System.out.println(LocalDate.of(2019, 12, 30).format(DateTimeFormatter.ofPattern("YYYYww", Locale.FRENCH))); + System.out.println(LocalDate.of(2019, 12, 30).format(DateTimeFormatter.ISO_WEEK_DATE)); + + DateTimeFormatter weekDateFormatter = new DateTimeFormatterBuilder() + .parseCaseInsensitive() + .appendValue(IsoFields.WEEK_BASED_YEAR, 4, 10, SignStyle.EXCEEDS_PAD) + .appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2) + .toFormatter(Locale.FRANCE); + + System.out.println(LocalDate.of(2019, 12, 30).format(weekDateFormatter)); + + // + logger.debug("===== test done."); + } + /** * After class. *