/**
 * ownCloud - Music app
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Morris Jobke <morris.jobke@gmail.com>
 * @author Pauli Järvinen <pauli.jarvinen@gmail.com>
 * @copyright 2013 Morris Jobke
 * @copyright 2020 Pauli Järvinen
 *
 */

angular.module('Music').filter('playTime', function() {
	return function(input) {
		var hours = Math.floor(input / 3600);
		var minutes = Math.floor((input - hours*3600) / 60);
		var seconds = Math.round(input % 60);

		if (hours > 0) {
			return hours + ':' + fmtTwoDigits(minutes) + ':' + fmtTwoDigits(seconds);
		} else {
			return minutes + ':' + fmtTwoDigits(seconds);
		}
	};

	// Format the given integer with two digits, prepending with a leading zero if necessary
	function fmtTwoDigits(integer) {
		return (integer < 10 ? '0' : '') + integer;
	}
});
/**
 * ownCloud - Music app
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Morris Jobke <morris.jobke@gmail.com>
 * @author Pauli Järvinen <pauli.jarvinen@gmail.com>
 * @copyright 2013 Morris Jobke
 * @copyright 2020, 2021 Pauli Järvinen
 *
 */

angular.module('Music').filter('playTime', function() {
	return function(input) {
		var hours = Math.floor(input / 3600);
		var minutes = Math.floor((input - hours*3600) / 60);
		var seconds = Math.floor(input % 60);

		if (hours > 0) {
			return hours + ':' + fmtTwoDigits(minutes) + ':' + fmtTwoDigits(seconds);
		} else {
			return minutes + ':' + fmtTwoDigits(seconds);
		}
	};

	// Format the given integer with two digits, prepending with a leading zero if necessary
	function fmtTwoDigits(integer) {
		return (integer < 10 ? '0' : '') + integer;
	}
});
Fix seconds part of play time showing incorrectly in range [59.5, 60.0)
Fix seconds part of play time showing incorrectly in range [59.5, 60.0)

This effectively rolls back the commit 989d5fb3. Using `round` instead
of `floor` for the seconds of the playtime wasn't such a great idea
after all, because it made the time stamp to show up like "0:60" for a
half a second before it changed to "1:00". It would have been possible
to keep the rounding to closest by altering the logic for minutes and
seconds parts, but the rounding had also a second minor issue: the play
time changed from 0:00 to 0:01 already after playing for half a second
which isn't quite how a time display is assumed to work, normally.

refs #814
