Converts a period string to a time.

<table>
<tr><td>ms<td>milliseconds
<tr><td>s<td>seconds
<tr><td>m<td>minutes
<tr><td>h<td>hours
<tr><td>D<td>days
<tr><td>W<td>weeks
<tr><td>M<td>months
<tr><td>Y<td>years
</table>
162686
public static long toPeriod(String value, long defaultUnits)
    throws ConfigException
  {
    if (value == null)
      return 0;
    
    long sign = 1;
    long period = 0;

    int i = 0;
    int length = value.length();
    
    if (length > 0 && value.charAt(i) == '-') {
      sign = -1;
      i++;
    }

    while (i < length) {
      long delta = 0;
      char ch;

      for (; i < length && (ch = value.charAt(i)) >= '0' && ch <= '9'; i++)
        delta = 10 * delta + ch - '0';

      if (length <= i)
        period += defaultUnits * delta;
      else {
        ch = value.charAt(i++);
        switch (ch) {
        case 's':
          period += 1000 * delta;
          break;

        case 'm':
          if (i < value.length() && value.charAt(i) == 's') {
            i++;
            period += delta;
          }
          else
            period += 60 * 1000 * delta;
          break;

        case 'h':
          period += 60L * 60 * 1000 * delta;
          break;

        case 'D':
          period += DAY * delta;
          break;

        case 'W':
          period += 7L * DAY * delta;
          break;

        case 'M':
          period += 30L * DAY * delta;
          break;

        case 'Y':
          period += 365L * DAY * delta;
          break;

        default:
          throw new ConfigException(L.l("Unknown unit `{0}' in period `{1}'. Valid units are:\n  '10ms' milliseconds\n  '10s' seconds\n  '10m' minutes\n  '10h' hours\n  '10D' days\n  '10W' weeks\n  '10M' months\n  '10Y' years",
                                        String.valueOf(ch), value));
        }
      }
    }

    period = sign * period;

    // server/137w
    /*
    if (period < 0)
      return INFINITE;
    else
      return period;
    */
    
    return period;
  }
975449
public static String formatDuration(long durationMs){
        Period period = Period.seconds((int)(durationMs/1000L));
        Period p2 = period.normalizedStandard(PeriodType.yearMonthDayTime());

        PeriodFormatter formatter = new PeriodFormatterBuilder()
                .appendYears()
                .appendSuffix(" yr ")
                .appendMonths()
                .appendSuffix(" months ")
                .appendDays()
                .appendSuffix(" days ")
                .appendHours()
                .appendSuffix(" hr ")
                .appendMinutes()
                .appendSuffix(" min ")
                .appendSeconds()
                .appendSuffix(" sec")
                .toFormatter();

        return formatter.print(p2);
    }
491124
public static String[] getHourMinuteSecondTimeString(long time) {

        int hours = (int)time / (1000 * 60 * 60);
        int min = (int)(time - (hours * 1000 * 60 * 60)) / (1000 * 60);
        int sec = (int)(time - (hours * 1000 * 60 * 60) - (min * 1000 * 60)) / 1000;

        return new String[] {getTwoDigitsString(hours), getTwoDigitsString(min), getTwoDigitsString(sec)};
    }
457365
def get_readable_time_string(seconds):
    """"""
    seconds = int(seconds)
    minutes = seconds // 60
    seconds = seconds % 60
    hours = minutes // 60
    minutes = minutes % 60
    days = hours // 24
    hours = hours % 24

    result = ""
    if days > 0:
        result += "%d %s " % (days, "Day" if (days == 1) else "Days")
    if hours > 0:
        result += "%d %s " % (hours, "Hour" if (hours == 1) else "Hours")
    if minutes > 0:
        result += "%d %s " % (minutes, "Minute" if (minutes == 1) else "Minutes")
    if seconds > 0:
        result += "%d %s " % (seconds, "Second" if (seconds == 1) else "Seconds")

    return result.strip()
1172166
function getTime(ts) {
		function pad2(n) {
			return n < 10 ? '0' + n : n;
		}

		function pad3(n) {
			return n < 10 ? '00' + n : (n < 100 ? '0' + n : n);
		}

		return pad2(ts.getHours()) + ':' +
			pad2(ts.getMinutes()) + ':' +
			pad2(ts.getSeconds()) + '.' +
			pad3(ts.getMilliseconds());
	}
423210
public static Duration parse(String value) {
		/*
		 * Implementation note: Regular expressions are not used to improve
		 * performance.
		 */

		if (value.length() == 0) {
			throw parseError(value);
		}

		int index = 0;
		char first = value.charAt(index);
		boolean prior = (first == '-');
		if (first == '-' || first == '+') {
			index++;
		}

		if (value.charAt(index) != 'P') {
			throw parseError(value);
		}

		Builder builder = new Builder();
		builder.prior(prior);

		StringBuilder buffer = new StringBuilder();
		for (int i = index + 1; i < value.length(); i++) {
			char c = value.charAt(i);

			if (c == 'T') {
				/*
				 * A "T" character is supposed to immediately precede the time
				 * component value(s). It is required by the syntax, but not
				 * really necessary. Ignore it.
				 */
				continue;
			}

			if (c >= '0' && c <= '9') {
				buffer.append(c);
				continue;
			}

			if (buffer.length() == 0) {
				throw parseError(value);
			}

			Integer num = Integer.valueOf(buffer.toString());
			buffer.setLength(0);

			switch (c) {
			case 'W':
				builder.weeks(num);
				break;
			case 'D':
				builder.days(num);
				break;
			case 'H':
				builder.hours(num);
				break;
			case 'M':
				builder.minutes(num);
				break;
			case 'S':
				builder.seconds(num);
				break;
			default:
				throw parseError(value);
			}
		}

		return builder.build();
	}
1342478
function toSeconds() {
      var seconds = this.seconds + 60 * this.minutes + 3600 * this.hours +
                    86400 * this.days + 7 * 86400 * this.weeks;
      return (this.isNegative ? -seconds : seconds);
    }
983708
def timedelta_isoformat(td: datetime.timedelta) -> str:
    
    minutes, seconds = divmod(td.seconds, 60)
    hours, minutes = divmod(minutes, 60)
    return f'P{td.days}DT{hours:d}H{minutes:d}M{seconds:d}.{td.microseconds:06d}S'
398547
def _str_to_time(self, str_value):
        """"""
        match = self.rx_time.match(str_value.upper())
        if not match:
            return None
        try:
            gd = match.groupdict()
            hour = int(gd['hour'])
            minute = int(gd['minute'])
            second = int(gd['second'] or 0)
            if gd['tt'] == 'PM':
                hour += 12
            return datetime.time(hour, minute, second)
        except (ValueError, TypeError):
            return None
142828
public static String createPeriodString(final ReadablePeriod period) {
    String periodStr = "null";

    if (period == null) {
      return periodStr;
    }

    if (period.get(DurationFieldType.years()) > 0) {
      final int years = period.get(DurationFieldType.years());
      periodStr = years + "y";
    } else if (period.get(DurationFieldType.months()) > 0) {
      final int months = period.get(DurationFieldType.months());
      periodStr = months + "M";
    } else if (period.get(DurationFieldType.weeks()) > 0) {
      final int weeks = period.get(DurationFieldType.weeks());
      periodStr = weeks + "w";
    } else if (period.get(DurationFieldType.days()) > 0) {
      final int days = period.get(DurationFieldType.days());
      periodStr = days + "d";
    } else if (period.get(DurationFieldType.hours()) > 0) {
      final int hours = period.get(DurationFieldType.hours());
      periodStr = hours + "h";
    } else if (period.get(DurationFieldType.minutes()) > 0) {
      final int minutes = period.get(DurationFieldType.minutes());
      periodStr = minutes + "m";
    } else if (period.get(DurationFieldType.seconds()) > 0) {
      final int seconds = period.get(DurationFieldType.seconds());
      periodStr = seconds + "s";
    }

    return periodStr;
  }
1208478
def get_period_strs(self, now=None):
        
        if now is None:
            now = self.dt.utcnow()

        year_str = "%04d" % now.year
        month_str = "%04d-%02d" % (now.year, now.month)
        day_str = "%04d-%02d-%02d" % (now.year, now.month, now.day)
        hour_str = "%04d-%02d-%02dT%02d" % (
            now.year, now.month, now.day, now.hour)

        # Note: The week number may be in the previous year during the last
        # days of the year.
        isocal = now.isocalendar()
        week_str = "%04d-W%02d" % (isocal[0], isocal[1])

        return {
            "year": year_str,
            "month": month_str,
            "day": day_str,
            "hour": hour_str,
            "week": week_str,
        }
185594
def gettime_s(text):
    
    pattern = r'([+-]?\d+\.?\d*) ?([munsecinh]+)'
    matches = re.findall(pattern, text)
    if len(matches) == 0:
        return None
    time = 0.
    for res in matches:
        tmp = float(res[0])
        if res[1] == 'ns':
            tmp *= 1e-9
        elif res[1] == 'us':
            tmp *= 1e-6
        elif res[1] == 'ms':
            tmp *= 1e-3
        elif res[1] == 'min':
            tmp *= 60
        elif res[1] == 'h':
            tmp *= 3600
        time += tmp
    return time
167562
private static String formatTime(long ms)
    {
        StringTokenizer st = new StringTokenizer(new Date(ms).toString());
        ArrayList<String>	arrayList = new ArrayList<>();
        while (st.hasMoreTokens())
            arrayList.add(st.nextToken());

        String  time  = arrayList.get(3);
        double d = (double)ms/1000;
        long   l = ms/1000;
        d = (d - l) * 1000;
        ms = (long) d;

        return time + "." + ms;
    }
83860
public static String toClock(long time)
	{

		long ttime = time;

		short miliseconds = (short) (ttime % 1000);
		ttime = ttime / 1000;

		short seconds = (short) (ttime % 60);
		ttime = ttime / 60;

		short minutes = (short) (ttime % 60);
		ttime = ttime / 60;

		short hours = (short) (ttime % 24);
		ttime = ttime / 24;

		short days = (short) (ttime % 7);
		short weeks = (short) (ttime / 7);

		StringBuilder s = new StringBuilder();

		s.append(((weeks * 7 + days) * 24 + hours) + ":");

		if (minutes < 10) {
			s.append('0');
		}
		s.append(minutes + ":");

		if (seconds < 10) {
			s.append('0');
		}
		s.append(seconds + ".");

		if (miliseconds < 100) {
			s.append('0');
		}
		if (miliseconds < 10) {
			s.append('0');
		}
		s.append(miliseconds);

		return s.toString();
	}
64940
private String getStrTime(Calendar c)
   {
      int h = c.get(Calendar.HOUR);
      int m = c.get(Calendar.MINUTE);
      int s = c.get(Calendar.SECOND);
      return "" + (h < 10 ? "0" + h : h) + (m < 10 ? "0" + m : m) + (s < 10 ? "0" + s : s);
   }
764181
def _read_time_from_string(str1):
    
    full_time = [float(x) for x in str1.split(':')]
    hour = int(full_time[0])
    minute = int(full_time[1])
    if full_time[2] > 59.99:
        minute += 1
        second = 0
    else:
        second = int(full_time[2])
    microseconds = int((full_time[2] - floor(full_time[2])) * 1000000)
    return datetime.time(hour, minute, second, microseconds)
148711
def timedelta_to_duration(dt):
    
    days, secs = dt.days, dt.seconds
    res = 'P'
    if days // 7:
        res += str(days // 7) + 'W'
        days %= 7
    if days:
        res += str(days) + 'D'
    if secs:
        res += 'T'
        if secs // 3600:
            res += str(secs // 3600) + 'H'
            secs %= 3600
        if secs // 60:
            res += str(secs // 60) + 'M'
            secs %= 60
        if secs:
            res += str(secs) + 'S'
    return res