Website Summary Files Commits Branches @commit @diff @stats
path: root / Week02 / Exercise06 / time.cpp
blob: 74b1447bb17801df4d93e214fd7013a63657febc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "time.h"

unsigned timeToMilliseconds(const Time& t) {
	return (t.hour * 60 * 60 + t.minutes * 60 + t.seconds) * 1000;
}

void Time::Advance(const Time& other) {
	// По-простия вариант е с експлицитни сметки, но помислете защо това работи
	*this = millisecondsToTime(timeToMilliseconds(*this) + timeToMilliseconds(other));
}

Time millisecondsToTime(unsigned int milliseconds) {
	Time t;
	t.hour    = (milliseconds / 1000 / 60 / 60) % 24;
	t.minutes = (milliseconds / 1000 / 60) % 60;
	t.seconds = (milliseconds / 1000) % 60;

	return t;
}