public static long parseDuration(String str) throws IllegalArgumentException {
        if (str == null)
            return 0;

        // Check for ISO_8601 format
        if (str.startsWith("P")) {
            // A common mistake is when the minutes format is intended but the month format is specified 
            // e.g. one month "P1M" is set, but one minute "PT1M" is meant.
            try {
                Duration dur = DatatypeFactory.newInstance().newDuration(str);
                return dur.getTimeInMillis(STATIC_DATE) / 1000;
            } catch (Exception ex) {
                throw new IllegalArgumentException("Cannot parse duration tag value: " + str, ex);
            }
        }

        try {
            int index = str.indexOf(":");
            if (index > 0) {
                String hourStr = str.substring(0, index);
                String minStr = str.substring(index + 1);
                String secondsStr = "0";
                index = minStr.indexOf(":");
                if (index > 0) {
                    secondsStr = minStr.substring(index + 1, index + 3);
                    minStr = minStr.substring(0, index);
                }

                long seconds = Integer.parseInt(hourStr) * 60L * 60;
                seconds += Integer.parseInt(minStr) * 60L;
                seconds += Integer.parseInt(secondsStr);
                return seconds;
            } else {
                // value contains minutes
                return Integer.parseInt(str) * 60L;
            }
        } catch (Exception ex) {
            throw new IllegalArgumentException("Cannot parse duration tag value: " + str, ex);
        }
    }
@Test
    public void testParseDuration() {
        assertEquals(10 * 60, OSMReaderUtility.parseDuration("00:10"));
        assertEquals(35 * 60, OSMReaderUtility.parseDuration("35"));
        assertEquals(70 * 60, OSMReaderUtility.parseDuration("01:10"));
        assertEquals(70 * 60 + 2, OSMReaderUtility.parseDuration("01:10:02"));
        assertEquals(0, OSMReaderUtility.parseDuration(null));
        assertEquals(60 * 20 * 60, OSMReaderUtility.parseDuration("20:00"));
        assertEquals(20 * 60, OSMReaderUtility.parseDuration("0:20:00"));
        assertEquals((60 * 2 + 20) * 60 + 2, OSMReaderUtility.parseDuration("02:20:02"));

        // two months
        assertEquals(31 + 31, OSMReaderUtility.parseDuration("P2M") / (24 * 60 * 60));

        // two minutes
        assertEquals(2 * 60, OSMReaderUtility.parseDuration("PT2M"));
        assertEquals((5 * 60 + 12) * 60 + 36, OSMReaderUtility.parseDuration("PT5H12M36S"));
    }