-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormat.cpp
More file actions
38 lines (31 loc) · 997 Bytes
/
Format.cpp
File metadata and controls
38 lines (31 loc) · 997 Bytes
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
// Author: mikedebo@gmail.com (Michael DiBernardo)
// Copyright Michael DiBernardo 2006
// Implementation of class Format and related constructs.
#include "Format.h"
#include <stdio.h>
#include <sstream>
using std::stringstream;
const int kNumMillisecondsInSecond = 1000;
const int kNumMillisecondsInMinute = 60 * kNumMillisecondsInSecond;
string Format::millisecondsToTicker(long ms) {
long minutes = ms / kNumMillisecondsInMinute;
ms -= minutes * kNumMillisecondsInMinute;
long seconds = ms / kNumMillisecondsInSecond;
ms -= seconds * kNumMillisecondsInSecond;
const int kBufSize = 9; // strlen("00:00:00") = 8, plus \0
char buf[kBufSize];
snprintf(buf, kBufSize, "%.2ld:%.2ld:%.2ld", minutes, seconds, ms);
return string(buf);
}
string Format::secondsToTicker(int s) {
return Format::millisecondsToTicker(s * 1000);
}
string Format::intToString(int num) {
stringstream ss;
string toReturn;
ss << num;
ss >> toReturn;
return toReturn;
}
Format::Format() {
}