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 5472e58..1c9deb1 100644 --- a/lib/dart_debug_sample.dart +++ b/lib/dart_debug_sample.dart @@ -1,81 +1,5 @@ import 'package:intl/intl.dart'; -class YukymController { - - // DateTime.parse(_userData.value!.selectDate) - String nowDate = DateFormat('yyyy-mm-dd').format(DateTime.now()); - - late String nowTime; - - // 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 - } - } - - 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; - } - - 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국'; @@ -89,4 +13,59 @@ class YukymTimeModel { String ty10 = '갑자10국'; String ty11 = '갑자11국'; String ty12 = '갑자12국'; +} + +class YukymController { + final DateTime dateTime; + YukymController({required this.dateTime}); + + String getTyA() { + final month = dateTime.month; + + if (month <= 2) { + return '경오1국'; + } else if (month <= 4) { + return '경오2국'; + } else if (month <= 6) { + return '경오3국'; + } else if (month <= 8) { + return '경오4국'; + } else if (month <= 10) { + return '경오5국'; + } else { + return '경오6국'; + } + } + + String getTyB() { + final timeModel = YukymTimeModel(); + + final hour = dateTime.hour; + + if (hour < 2) { + return timeModel.ty1; + } else if (hour < 4) { + return timeModel.ty2; + } else if (hour < 6) { + return timeModel.ty3; + } else if (hour < 8) { + return timeModel.ty4; + } else if (hour < 10) { + return timeModel.ty5; + } else if (hour < 12) { + return timeModel.ty6; + } else if (hour < 14) { + return timeModel.ty7; + } else if (hour < 16) { + return timeModel.ty8; + } else if (hour < 18) { + return timeModel.ty9; + } else if (hour < 20) { + return timeModel.ty10; + } else if (hour < 22) { + return timeModel.ty11; + } else { + return timeModel.ty12; + } + } } \ No newline at end of file