@Test public void testGetTimeInMillis() { long result = ((DefaultPeriodDuration) periodDuration1).getTimeInMillis(); assertFalse(((DefaultPeriodDuration) periodDuration2).getTimeInMillis() == result); }
public long getTimeInMillis() { String periodDescription = this.toString(); long yearMS = 31536000000L; long monthMS = 2628000000L; long weekMS = 604800000L; long dayMS = 86400000L; long hourMS = 3600000L; long minMS = 60000L; long secondMS = 1000L; long response = 0; periodDescription = periodDescription.substring(1); if (periodDescription.indexOf('Y') != -1) { int nbYear = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('Y'))); response += nbYear * yearMS; periodDescription = periodDescription.substring(periodDescription.indexOf('Y') + 1); } if ((periodDescription.indexOf('M') != -1 && (periodDescription.indexOf('T') == -1)) || ((periodDescription.indexOf('T') != -1) && (periodDescription.indexOf('M') < periodDescription.indexOf('T')) && ((periodDescription.indexOf('M') != -1)))) { int nbMonth = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMonth * monthMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('W') != -1) { int nbWeek = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('W'))); response += nbWeek * weekMS; periodDescription = periodDescription.substring(periodDescription.indexOf('W') + 1); } if (periodDescription.indexOf('D') != -1) { int nbDay = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('D'))); response += nbDay * dayMS; periodDescription = periodDescription.substring(periodDescription.indexOf('D') + 1); } if (periodDescription.indexOf('T') != -1) { periodDescription = periodDescription.substring(1); } if (periodDescription.indexOf('H') != -1) { int nbHour = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('H'))); response += nbHour * hourMS; periodDescription = periodDescription.substring(periodDescription.indexOf('H') + 1); } if (periodDescription.indexOf('M') != -1) { int nbMin = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMin * minMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('S') != -1) { int nbSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('S'))); response += nbSec * secondMS; periodDescription = periodDescription.substring(periodDescription.indexOf('S') + 1); } if (periodDescription.length() != 0) { throw new IllegalArgumentException("The period duration string is malformed"); } return response; }
DefaultPeriodDuration extends DefaultDuration implements PeriodDuration { public long getTimeInMillis() { String periodDescription = this.toString(); long yearMS = 31536000000L; long monthMS = 2628000000L; long weekMS = 604800000L; long dayMS = 86400000L; long hourMS = 3600000L; long minMS = 60000L; long secondMS = 1000L; long response = 0; periodDescription = periodDescription.substring(1); if (periodDescription.indexOf('Y') != -1) { int nbYear = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('Y'))); response += nbYear * yearMS; periodDescription = periodDescription.substring(periodDescription.indexOf('Y') + 1); } if ((periodDescription.indexOf('M') != -1 && (periodDescription.indexOf('T') == -1)) || ((periodDescription.indexOf('T') != -1) && (periodDescription.indexOf('M') < periodDescription.indexOf('T')) && ((periodDescription.indexOf('M') != -1)))) { int nbMonth = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMonth * monthMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('W') != -1) { int nbWeek = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('W'))); response += nbWeek * weekMS; periodDescription = periodDescription.substring(periodDescription.indexOf('W') + 1); } if (periodDescription.indexOf('D') != -1) { int nbDay = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('D'))); response += nbDay * dayMS; periodDescription = periodDescription.substring(periodDescription.indexOf('D') + 1); } if (periodDescription.indexOf('T') != -1) { periodDescription = periodDescription.substring(1); } if (periodDescription.indexOf('H') != -1) { int nbHour = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('H'))); response += nbHour * hourMS; periodDescription = periodDescription.substring(periodDescription.indexOf('H') + 1); } if (periodDescription.indexOf('M') != -1) { int nbMin = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMin * minMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('S') != -1) { int nbSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('S'))); response += nbSec * secondMS; periodDescription = periodDescription.substring(periodDescription.indexOf('S') + 1); } if (periodDescription.length() != 0) { throw new IllegalArgumentException("The period duration string is malformed"); } return response; } }
DefaultPeriodDuration extends DefaultDuration implements PeriodDuration { public long getTimeInMillis() { String periodDescription = this.toString(); long yearMS = 31536000000L; long monthMS = 2628000000L; long weekMS = 604800000L; long dayMS = 86400000L; long hourMS = 3600000L; long minMS = 60000L; long secondMS = 1000L; long response = 0; periodDescription = periodDescription.substring(1); if (periodDescription.indexOf('Y') != -1) { int nbYear = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('Y'))); response += nbYear * yearMS; periodDescription = periodDescription.substring(periodDescription.indexOf('Y') + 1); } if ((periodDescription.indexOf('M') != -1 && (periodDescription.indexOf('T') == -1)) || ((periodDescription.indexOf('T') != -1) && (periodDescription.indexOf('M') < periodDescription.indexOf('T')) && ((periodDescription.indexOf('M') != -1)))) { int nbMonth = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMonth * monthMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('W') != -1) { int nbWeek = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('W'))); response += nbWeek * weekMS; periodDescription = periodDescription.substring(periodDescription.indexOf('W') + 1); } if (periodDescription.indexOf('D') != -1) { int nbDay = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('D'))); response += nbDay * dayMS; periodDescription = periodDescription.substring(periodDescription.indexOf('D') + 1); } if (periodDescription.indexOf('T') != -1) { periodDescription = periodDescription.substring(1); } if (periodDescription.indexOf('H') != -1) { int nbHour = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('H'))); response += nbHour * hourMS; periodDescription = periodDescription.substring(periodDescription.indexOf('H') + 1); } if (periodDescription.indexOf('M') != -1) { int nbMin = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMin * minMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('S') != -1) { int nbSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('S'))); response += nbSec * secondMS; periodDescription = periodDescription.substring(periodDescription.indexOf('S') + 1); } if (periodDescription.length() != 0) { throw new IllegalArgumentException("The period duration string is malformed"); } return response; } DefaultPeriodDuration(InternationalString years, InternationalString months, InternationalString week, InternationalString days,
            InternationalString hours, InternationalString minutes, InternationalString seconds);  DefaultPeriodDuration(long durationInMilliSeconds); }
DefaultPeriodDuration extends DefaultDuration implements PeriodDuration { public long getTimeInMillis() { String periodDescription = this.toString(); long yearMS = 31536000000L; long monthMS = 2628000000L; long weekMS = 604800000L; long dayMS = 86400000L; long hourMS = 3600000L; long minMS = 60000L; long secondMS = 1000L; long response = 0; periodDescription = periodDescription.substring(1); if (periodDescription.indexOf('Y') != -1) { int nbYear = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('Y'))); response += nbYear * yearMS; periodDescription = periodDescription.substring(periodDescription.indexOf('Y') + 1); } if ((periodDescription.indexOf('M') != -1 && (periodDescription.indexOf('T') == -1)) || ((periodDescription.indexOf('T') != -1) && (periodDescription.indexOf('M') < periodDescription.indexOf('T')) && ((periodDescription.indexOf('M') != -1)))) { int nbMonth = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMonth * monthMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('W') != -1) { int nbWeek = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('W'))); response += nbWeek * weekMS; periodDescription = periodDescription.substring(periodDescription.indexOf('W') + 1); } if (periodDescription.indexOf('D') != -1) { int nbDay = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('D'))); response += nbDay * dayMS; periodDescription = periodDescription.substring(periodDescription.indexOf('D') + 1); } if (periodDescription.indexOf('T') != -1) { periodDescription = periodDescription.substring(1); } if (periodDescription.indexOf('H') != -1) { int nbHour = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('H'))); response += nbHour * hourMS; periodDescription = periodDescription.substring(periodDescription.indexOf('H') + 1); } if (periodDescription.indexOf('M') != -1) { int nbMin = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMin * minMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('S') != -1) { int nbSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('S'))); response += nbSec * secondMS; periodDescription = periodDescription.substring(periodDescription.indexOf('S') + 1); } if (periodDescription.length() != 0) { throw new IllegalArgumentException("The period duration string is malformed"); } return response; } DefaultPeriodDuration(InternationalString years, InternationalString months, InternationalString week, InternationalString days,
            InternationalString hours, InternationalString minutes, InternationalString seconds);  DefaultPeriodDuration(long durationInMilliSeconds); InternationalString getDesignator(); InternationalString getYears(); InternationalString getMonths(); InternationalString getDays(); InternationalString getTimeIndicator(); InternationalString getHours(); InternationalString getMinutes(); InternationalString getSeconds(); void setYears(InternationalString years); void setMonths(InternationalString months); void setDays(InternationalString days); void setHours(InternationalString hours); void setMinutes(InternationalString minutes); void setSeconds(InternationalString seconds); InternationalString getWeek(); void setWeek(InternationalString week); long getTimeInMillis(); @Override boolean equals(final Object object); @Override int hashCode(); @Override /** * Returns a duration value String in format 8601. the pattern is PnYnMnDTnHnMnS. */ String toString(); }
DefaultPeriodDuration extends DefaultDuration implements PeriodDuration { public long getTimeInMillis() { String periodDescription = this.toString(); long yearMS = 31536000000L; long monthMS = 2628000000L; long weekMS = 604800000L; long dayMS = 86400000L; long hourMS = 3600000L; long minMS = 60000L; long secondMS = 1000L; long response = 0; periodDescription = periodDescription.substring(1); if (periodDescription.indexOf('Y') != -1) { int nbYear = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('Y'))); response += nbYear * yearMS; periodDescription = periodDescription.substring(periodDescription.indexOf('Y') + 1); } if ((periodDescription.indexOf('M') != -1 && (periodDescription.indexOf('T') == -1)) || ((periodDescription.indexOf('T') != -1) && (periodDescription.indexOf('M') < periodDescription.indexOf('T')) && ((periodDescription.indexOf('M') != -1)))) { int nbMonth = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMonth * monthMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('W') != -1) { int nbWeek = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('W'))); response += nbWeek * weekMS; periodDescription = periodDescription.substring(periodDescription.indexOf('W') + 1); } if (periodDescription.indexOf('D') != -1) { int nbDay = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('D'))); response += nbDay * dayMS; periodDescription = periodDescription.substring(periodDescription.indexOf('D') + 1); } if (periodDescription.indexOf('T') != -1) { periodDescription = periodDescription.substring(1); } if (periodDescription.indexOf('H') != -1) { int nbHour = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('H'))); response += nbHour * hourMS; periodDescription = periodDescription.substring(periodDescription.indexOf('H') + 1); } if (periodDescription.indexOf('M') != -1) { int nbMin = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('M'))); response += nbMin * minMS; periodDescription = periodDescription.substring(periodDescription.indexOf('M') + 1); } if (periodDescription.indexOf('S') != -1) { int nbSec = Integer.parseInt(periodDescription.substring(0, periodDescription.indexOf('S'))); response += nbSec * secondMS; periodDescription = periodDescription.substring(periodDescription.indexOf('S') + 1); } if (periodDescription.length() != 0) { throw new IllegalArgumentException("The period duration string is malformed"); } return response; } DefaultPeriodDuration(InternationalString years, InternationalString months, InternationalString week, InternationalString days,
            InternationalString hours, InternationalString minutes, InternationalString seconds);  DefaultPeriodDuration(long durationInMilliSeconds); InternationalString getDesignator(); InternationalString getYears(); InternationalString getMonths(); InternationalString getDays(); InternationalString getTimeIndicator(); InternationalString getHours(); InternationalString getMinutes(); InternationalString getSeconds(); void setYears(InternationalString years); void setMonths(InternationalString months); void setDays(InternationalString days); void setHours(InternationalString hours); void setMinutes(InternationalString minutes); void setSeconds(InternationalString seconds); InternationalString getWeek(); void setWeek(InternationalString week); long getTimeInMillis(); @Override boolean equals(final Object object); @Override int hashCode(); @Override /** * Returns a duration value String in format 8601. the pattern is PnYnMnDTnHnMnS. */ String toString();  }