From 908b02166ed53a1f872ddbf92cc117428d6dcdc0 Mon Sep 17 00:00:00 2001 From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com> Date: Thu, 4 Nov 2021 22:48:52 +0900 Subject: [PATCH] feat: add getCycle method --- src/com/ranfa/lib/EstimateAlbumTypeCycle.java | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/com/ranfa/lib/EstimateAlbumTypeCycle.java b/src/com/ranfa/lib/EstimateAlbumTypeCycle.java index 46d4c6e..dac911d 100644 --- a/src/com/ranfa/lib/EstimateAlbumTypeCycle.java +++ b/src/com/ranfa/lib/EstimateAlbumTypeCycle.java @@ -11,6 +11,7 @@ import javax.swing.JOptionPane; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; +import com.sun.org.apache.bcel.internal.generic.NEW; public class EstimateAlbumTypeCycle { @@ -45,11 +46,34 @@ public class EstimateAlbumTypeCycle { private static void write(AlbumCycleDefinitionProperty property) { ObjectWriter writer = new ObjectMapper().writer(new DefaultPrettyPrinter()); try { - writer.writeValue(Paths.get(CYCLEPATH).toFile(), writer); + writer.writeValue(Paths.get(CYCLEPATH).toFile(), property); } catch (IOException e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } } + public static String getCurrentCycle() { + if(Files.notExists(Paths.get(CYCLEPATH))) + throw new IllegalStateException("Program seems to have avoided first initiating. how could it have done?"); + AlbumCycleDefinitionProperty property = new AlbumCycleDefinitionProperty(); + try { + property = new ObjectMapper().readValue(Paths.get(CYCLEPATH).toFile(), AlbumCycleDefinitionProperty.class); + } catch (IOException e) { + e.printStackTrace(); + } + int dayPresent = Integer.parseInt(new SimpleDateFormat("DD").format(new Date())); + int dayDefinited = Integer.parseInt(property.getDateDefinited().substring(8)); + int daysLeft = property.getDaysLeft(); + if(dayPresent - dayDefinited <= 1 && daysLeft == 0) { + int delta = dayPresent - dayDefinited; + int weeksPassed = delta / 14; + if(weeksPassed > 0) { + int weeksPassedDelta = weeksPassed / 3; + + } + } + return property.getType(); + } + } -- 2.11.0