From 4e29cbc23798a3894aaf3af211903e652f310686 Mon Sep 17 00:00:00 2001 From: Moon <1tjsen@naver.com> Date: Thu, 26 Jun 2025 18:57:05 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20getTyA=EA=B0=80=20=EA=B0=91=EC=9E=90?= =?UTF-8?q?1=EA=B5=AD=EC=9D=84=20=EB=A6=AC=ED=84=B4=ED=95=98=EB=8D=98=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/dart_debug_sample.dart | 39 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/lib/dart_debug_sample.dart b/lib/dart_debug_sample.dart index 5472e58..8c932ac 100644 --- a/lib/dart_debug_sample.dart +++ b/lib/dart_debug_sample.dart @@ -1,7 +1,6 @@ import 'package:intl/intl.dart'; class YukymController { - // DateTime.parse(_userData.value!.selectDate) String nowDate = DateFormat('yyyy-mm-dd').format(DateTime.now()); @@ -9,31 +8,21 @@ class YukymController { // 1. 자시의 국 : 갑자1국 = getTyOne()의 값 String getTyA() { - List timeDataOne = - _getTimeDataOne(nowDate); - - if (timeDataOne.isNotEmpty) { - nowTime = timeDataOne.first.ty1; - - final month = nowDate.substring(5, 7); - if (month == '01' || month == '02') { - return '경오1국'; - } else if (month == '03' || month == '04') { - return '경오2국'; - } else if (month == '05' || month == '06') { - return '경오3국'; - } else if (month == '07' || month == '08') { - return '경오4국'; - } else if (month == '09' || month == '10') { - return '경오5국'; - } else if (month == '11' || month == '12') { - return '경오6국'; - } - return nowTime; - } else { - // Handle the case when the list is empty - return '경오7국'; // Or any other appropriate action + final month = DateTime.now().month; + if (month == 1 || month == 2) { + return '경오1국'; + } else if (month == 3 || month == 4) { + return '경오2국'; + } else if (month == 5 || month == 6) { + return '경오3국'; + } else if (month == 7 || month == 8) { + return '경오4국'; + } else if (month == 9 || month == 10) { + return '경오5국'; + } else if (month == 11 || month == 12) { + return '경오6국'; } + return '경오7국'; } String getTyB() { From 27b99044859e014ae573f7cd59947f2fe76e1f9e Mon Sep 17 00:00:00 2001 From: Moon <1tjsen@naver.com> Date: Thu, 26 Jun 2025 18:57:33 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20getTyB=EA=B0=80=20=EA=B0=91=EC=9E=90?= =?UTF-8?q?1=EA=B5=AD=EB=A7=8C=20=EB=A6=AC=ED=84=B4=ED=95=98=EB=8D=98=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/dart_debug_sample.dart | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/dart_debug_sample.dart b/lib/dart_debug_sample.dart index 8c932ac..0d96ebf 100644 --- a/lib/dart_debug_sample.dart +++ b/lib/dart_debug_sample.dart @@ -26,30 +26,29 @@ class YukymController { } String getTyB() { - List timeDataOne = - _getTimeDataOne(nowDate); + List timeDataOne = _getTimeDataOne(nowDate); String result = timeDataOne.first.ty12; final nowTime = DateTime.now(); - if (nowTime.hour >= 0 || nowTime.hour < 2) { + if (nowTime.hour >= 0 && nowTime.hour < 2) { return timeDataOne.first.ty1; - } else if (nowTime.hour >= 4 || nowTime.hour < 6) { + } else if (nowTime.hour >= 4 && nowTime.hour < 6) { return timeDataOne.first.ty2; - } else if (nowTime.hour >= 6 || nowTime.hour < 8) { + } else if (nowTime.hour >= 6 && nowTime.hour < 8) { return timeDataOne.first.ty3; - } else if (nowTime.hour >= 8 || nowTime.hour < 10) { + } else if (nowTime.hour >= 8 && nowTime.hour < 10) { return timeDataOne.first.ty4; - } else if (nowTime.hour >= 10 || nowTime.hour < 12) { + } else if (nowTime.hour >= 10 && nowTime.hour < 12) { return timeDataOne.first.ty5; - } else if (nowTime.hour >= 12 || nowTime.hour < 14) { + } else if (nowTime.hour >= 12 && nowTime.hour < 14) { return timeDataOne.first.ty6; - } else if (nowTime.hour >= 16 || nowTime.hour < 18) { + } else if (nowTime.hour >= 16 && nowTime.hour < 18) { return timeDataOne.first.ty7; - } else if (nowTime.hour >= 18 || nowTime.hour < 20) { + } else if (nowTime.hour >= 18 && nowTime.hour < 20) { return timeDataOne.first.ty8; - } else if (nowTime.hour >= 20 || nowTime.hour < 22) { + } else if (nowTime.hour >= 20 && nowTime.hour < 22) { return timeDataOne.first.ty9; - } else if (nowTime.hour >= 22 || nowTime.hour < 24) { + } else if (nowTime.hour >= 22 && nowTime.hour < 24) { return timeDataOne.first.ty10; } @@ -78,4 +77,4 @@ class YukymTimeModel { String ty10 = '갑자10국'; String ty11 = '갑자11국'; String ty12 = '갑자12국'; -} \ No newline at end of file +} From d78f5852c382c1a02c0169f67e985c011175313c Mon Sep 17 00:00:00 2001 From: Moon <1tjsen@naver.com> Date: Thu, 26 Jun 2025 22:00:14 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20if=EB=A5=BC=20switch=EB=A1=9C?= =?UTF-8?q?=20=EA=B5=90=EC=B2=B4,=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/dart_debug_sample.dart | 2 +- lib/dart_debug_sample.dart | 115 ++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 68 deletions(-) diff --git a/bin/dart_debug_sample.dart b/bin/dart_debug_sample.dart index f6f44b2..b10f0a7 100644 --- a/bin/dart_debug_sample.dart +++ b/bin/dart_debug_sample.dart @@ -1,7 +1,7 @@ import 'package:dart_debug_sample/dart_debug_sample.dart'; void main() { - YukymController yukymController = YukymController(); + YukymController yukymController = YukymController(dateTime: DateTime.now()); print(yukymController.getTyA()); // 해당 월에 맞는 자시의 국 표시 print(yukymController.getTyB()); // 해당 시간에 맞는 자시의 국 표시 } diff --git a/lib/dart_debug_sample.dart b/lib/dart_debug_sample.dart index 0d96ebf..e0f1408 100644 --- a/lib/dart_debug_sample.dart +++ b/lib/dart_debug_sample.dart @@ -1,80 +1,61 @@ -import 'package:intl/intl.dart'; - class YukymController { - // DateTime.parse(_userData.value!.selectDate) - String nowDate = DateFormat('yyyy-mm-dd').format(DateTime.now()); + final DateTime dateTime; - late String nowTime; + YukymController({required this.dateTime}); - // 1. 자시의 국 : 갑자1국 = getTyOne()의 값 String getTyA() { - final month = DateTime.now().month; - if (month == 1 || month == 2) { - return '경오1국'; - } else if (month == 3 || month == 4) { - return '경오2국'; - } else if (month == 5 || month == 6) { - return '경오3국'; - } else if (month == 7 || month == 8) { - return '경오4국'; - } else if (month == 9 || month == 10) { - return '경오5국'; - } else if (month == 11 || month == 12) { - return '경오6국'; + final month = dateTime.month; + var result = '경오7국'; + + switch (month) { + case 1 || 2: + result = '경오1국'; + case 3 || 4: + result = '경오2국'; + case 5 || 6: + result = '경오3국'; + case 7 || 8: + result = '경오4국'; + case 9 || 10: + result = '경오5국'; + case 11 || 12: + result = '경오6국'; } - return '경오7국'; + + return result; } String getTyB() { - List timeDataOne = _getTimeDataOne(nowDate); - String result = timeDataOne.first.ty12; - - final nowTime = DateTime.now(); - if (nowTime.hour >= 0 && nowTime.hour < 2) { - return timeDataOne.first.ty1; - } else if (nowTime.hour >= 4 && nowTime.hour < 6) { - return timeDataOne.first.ty2; - } else if (nowTime.hour >= 6 && nowTime.hour < 8) { - return timeDataOne.first.ty3; - } else if (nowTime.hour >= 8 && nowTime.hour < 10) { - return timeDataOne.first.ty4; - } else if (nowTime.hour >= 10 && nowTime.hour < 12) { - return timeDataOne.first.ty5; - } else if (nowTime.hour >= 12 && nowTime.hour < 14) { - return timeDataOne.first.ty6; - } else if (nowTime.hour >= 16 && nowTime.hour < 18) { - return timeDataOne.first.ty7; - } else if (nowTime.hour >= 18 && nowTime.hour < 20) { - return timeDataOne.first.ty8; - } else if (nowTime.hour >= 20 && nowTime.hour < 22) { - return timeDataOne.first.ty9; - } else if (nowTime.hour >= 22 && nowTime.hour < 24) { - return timeDataOne.first.ty10; + final hour = dateTime.hour; + var result = '갑자1국'; + + switch (hour) { + case >= 0 && < 2: + result = '갑자1국'; + case >= 2 && < 4: + result = '갑자2국'; + case >= 4 && < 6: + result = '갑자3국'; + case >= 6 && < 8: + result = '갑자4국'; + case >= 8 && < 10: + result = '갑자5국'; + case >= 10 && < 12: + result = '갑자6국'; + case >= 12 && < 14: + result = '갑자7국'; + case >= 14 && < 16: + result = '갑자8국'; + case >= 16 && < 18: + result = '갑자9국'; + case >= 18 && < 20: + result = '갑자10국'; + case >= 20 && < 22: + result = '갑자11국'; + case >= 22 && < 24: + result = '갑자12국'; } return result; } - - List _getTimeDataOne(String nowDate) { - List timeDataOne = []; - for (int i = 0; i < 24; i++) { - timeDataOne.add(YukymTimeModel()); - } - return timeDataOne; - } -} - -class YukymTimeModel { - String ty1 = '갑자1국'; - String ty2 = '갑자2국'; - String ty3 = '갑자3국'; - String ty4 = '갑자4국'; - String ty5 = '갑자5국'; - String ty6 = '갑자6국'; - String ty7 = '갑자7국'; - String ty8 = '갑자8국'; - String ty9 = '갑자9국'; - String ty10 = '갑자10국'; - String ty11 = '갑자11국'; - String ty12 = '갑자12국'; }