static long stringToSeconds(String time) throws NumberFormatException, DateTimeParseException
	{
		long duration = 0;

		if (time.matches(INPUT_HMS_REGEX))
		{
			String textWithoutWhitespaces = time.replaceAll(WHITESPACE_REGEX, "");
			//parse input using ISO-8601 Duration format (e.g. 'PT1h30m10s')
			duration = Duration.parse("PT" + textWithoutWhitespaces).toMillis() / 1000;
		}
		else
		{
			String[] parts = time.split(":");
			// parse from back to front, so as to accept hour:min:sec, min:sec, and sec formats
			for (int i = parts.length - 1, multiplier = 1; i >= 0 && multiplier <= 3600; i--, multiplier *= 60)
			{
				duration += Integer.parseInt(parts[i].trim()) * multiplier;
			}
		}

		return duration;
	}
@Test
	public void properColonSeparatedTimeStringShouldReturnCorrectSeconds()
	{
		assertEquals(5, ClockPanel.stringToSeconds("5"));
		assertEquals(50, ClockPanel.stringToSeconds("50"));
		assertEquals(120, ClockPanel.stringToSeconds("2:00"));
		assertEquals(120, ClockPanel.stringToSeconds("0:120"));
		assertEquals(120, ClockPanel.stringToSeconds("0:0:120"));
		assertEquals(1200, ClockPanel.stringToSeconds("20:00"));

		assertEquals(50, ClockPanel.stringToSeconds("00:00:50"));
		assertEquals(121, ClockPanel.stringToSeconds("00:02:01"));
		assertEquals(3660, ClockPanel.stringToSeconds("01:01:00"));
		assertEquals(9000, ClockPanel.stringToSeconds("2:30:00"));
		assertEquals(9033, ClockPanel.stringToSeconds("02:30:33"));
		assertEquals(82800, ClockPanel.stringToSeconds("23:00:00"));
		assertEquals(400271, ClockPanel.stringToSeconds("111:11:11"));
	}