1/*
2 * Copyright 2010, Stephan A��mus <superstippi@gmx.de>
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "DurationToString.h"
8
9#include <stdio.h>
10
11
12void
13duration_to_string(int32 seconds, char* string, size_t stringSize)
14{
15	bool negative = seconds < 0;
16	if (negative)
17		seconds = -seconds;
18
19	int32 hours = seconds / 3600;
20	seconds -= hours * 3600;
21	int32 minutes = seconds / 60;
22	seconds = seconds % 60;
23
24	if (hours > 0) {
25		snprintf(string, stringSize, "%s%" B_PRId32 ":%02" B_PRId32 ":%02"
26			B_PRId32, negative ? "-" : "", hours, minutes, seconds);
27	} else {
28		snprintf(string, stringSize, "%s%" B_PRId32 ":%02" B_PRId32,
29			negative ? "-" : "", minutes, seconds);
30	}
31}
32