-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatting.h
69 lines (53 loc) · 1019 Bytes
/
formatting.h
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
#pragma once
#include <Arduino.h>
String minutes_to_time(int mins)
{
int hrs = mins / 60;
int leftover_mins = mins - hrs * 60;
String mins_part = String(leftover_mins);
if (leftover_mins < 10)
{
mins_part = "0" + mins_part;
}
String result = String(hrs) + ":" + mins_part;
if (hrs < 10)
{
result = "0" + result;
}
return result;
}
String minutes_to_duration(int mins)
{
if (mins == 0)
{
return "instant";
}
String result = "";
int hrs = mins / 60;
int leftover_mins = mins - hrs * 60;
if (hrs > 1)
{
result += String(hrs) + "hrs";
}
else if (hrs != 0)
{
result += String(hrs) + "hr";
}
if (hrs && leftover_mins)
{
result += " ";
}
if (leftover_mins > 0)
{
result += String(leftover_mins) + " mins";
}
return result;
}
String left_pad(int v)
{
if (v < 10)
{
return "0" + String(v);
}
return String(v);
}