https://www.jdoodle.com/execute-dart-online/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | void calcRemain(DateTime t1,DateTime t2) {
var cd_min = '00';
var cd_sec = '00';
var _cd = t1.difference(t2).inSeconds;
var _cd_min = _cd ~/ 60;
var _cd_sec = _cd%60;
if (_cd_min < 10) {
cd_min = '0' + _cd_min.toString();
} else {
cd_min = _cd_min.toString();
}
if (_cd_sec < 10) {
cd_sec = '0' + _cd_sec.toString();
} else {
cd_sec = _cd_sec.toString();
}
print('remain: ${cd_min}:${cd_sec}');
}
void main() {
print('Hello, Dart!');
const int pomo = 25;//min
const int s_rest = 5;//min
const int l_rest = 15;//min
final tempotime = DateTime.now();
final finish_time = tempotime.add(const Duration(minutes: pomo*4 + s_rest*3 + l_rest*1));
print('start time -> ${tempotime.hour}:${tempotime.minute}:${tempotime.second}');
print('finish time: ${finish_time.hour}:${finish_time.minute}:${finish_time.second}');
var pomo_1_rest = tempotime.add(const Duration(seconds: pomo*1*60));
var pomo_2_ = tempotime.add(const Duration(seconds: (pomo*1 + s_rest*1)*60));
var pomo_2_rest = tempotime.add(const Duration(seconds: (pomo*2 + s_rest*1)*60));
var pomo_3_ = tempotime.add(const Duration(seconds: (pomo*2 + s_rest*2)*60));
var pomo_3_rest = tempotime.add(const Duration(seconds: (pomo*3 + s_rest*2)*60));
var pomo_4_ = tempotime.add(const Duration(seconds: (pomo*3 + s_rest*3)*60));
var pomo_4_rest = tempotime.add(const Duration(seconds: (pomo*4 + s_rest*3)*60));
var t = tempotime;
while(finish_time.difference(t).inSeconds > 0){
var t2 = DateTime.now();
if (t2.difference(t).inSeconds == 1) {
print('');
print('${t2.hour}:${t2.minute}:${t2.second} -> finish time: ${finish_time.hour}:${finish_time.minute}:${finish_time.second}');
var _diff = t2.difference(tempotime).inSeconds;
var _diff_min = _diff ~/ 60;
var _diff_sec = _diff%60;
var _min = '00';
var _sec = '00';
if (_diff_min < 10) {
_min = '0' + _diff_min.toString();
} else {
_min = _diff_min.toString();
}
if (_diff_sec < 10) {
_sec = '0' + _diff_sec.toString();
} else {
_sec = _diff_sec.toString();
}
print('past time: ${_min}:${_sec}');
t = t2;
if (t2.isBefore(pomo_1_rest)) {
//pomodoro 1
calcRemain(pomo_1_rest,t2);
print('pomodoro 1');
}
else if (t2.isBefore(pomo_2_rest) && t2.isAfter(pomo_2_)) {
//pomodoro 2
calcRemain(pomo_2_rest,t2);
print('pomodoro 2');
}
else if (t2.isBefore(pomo_3_rest) && t2.isAfter(pomo_3_)) {
//pomodoro 3
calcRemain(pomo_3_rest,t2);
print('pomodoro 3');
}
else if (t2.isBefore(pomo_4_rest) && t2.isAfter(pomo_4_)) {
//pomodoro 4
calcRemain(pomo_4_rest,t2);
print('pomodoro 4');
}
else if (t2.isAfter(pomo_4_rest)) {
//rest 4
calcRemain(finish_time,t2);
print('rest 4');
}
else if (t2.isAfter(pomo_3_rest) && t2.isBefore(pomo_4_)) {
//rest 3
calcRemain(pomo_4_,t2);
print('rest 3');
}
else if (t2.isAfter(pomo_2_rest) && t2.isBefore(pomo_3_)) {
//rest 2
calcRemain(pomo_3_,t2);
print('rest 2');
}
else if (t2.isAfter(pomo_1_rest) && t2.isBefore(pomo_2_)) {
//rest 1
calcRemain(pomo_2_,t2);
print('rest 1');
}
}
}
}
|