Class TimeUtils

java.lang.Object
com.dianxin.tori.base.utils.TimeUtils

public final class TimeUtils extends Object
[EN] Utility class for handling time formatting and parsing.
Primarily used for media playback features like seeking and duration display.

[VN] Lớp tiện ích để xử lý việc định dạng và phân tích thời gian.
Chủ yếu được sử dụng cho các tính năng phát phương tiện như tua (seek) và hiển thị thời lượng.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    [EN] Record to store the result of time parsing.
    Contains the calculated duration and whether the seek is relative to current position.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    formatTime(long duration)
    [EN] Formats a duration in milliseconds into a human-readable string.
    Format: HH:MM:SS or MM:SS.
    static long
    [EN] Parses a timestamp formatted with colons.
    Format accepted: HH:MM:SS, MM:SS, or SS.
    [EN] Parses a seek time string into milliseconds and determines if it's relative.
    Supports "colon time" (e.g., 1:20:30) or "unit time" (e.g., 1h20m).
    Also detects relative seeking (starting with + or -).
    static long
    [EN] Parses a time string formatted with units.
    Examples: 20m10s, 1d5h, 1h and 20m.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TimeUtils

      public TimeUtils()
  • Method Details

    • formatTime

      public static String formatTime(long duration)
      [EN] Formats a duration in milliseconds into a human-readable string.
      Format: HH:MM:SS or MM:SS. Returns "LIVE" if duration is Long.MAX_VALUE.

      [VN] Định dạng khoảng thời gian (mili giây) thành chuỗi dễ đọc.
      Định dạng: HH:MM:SS hoặc MM:SS. Trả về "LIVE" nếu thời lượng là Long.MAX_VALUE.
      Parameters:
      duration - [EN] Time in milliseconds.
      [VN] Thời gian tính bằng mili giây.
      Returns:
      [EN] Formatted time string.
      [VN] Chuỗi thời gian đã được định dạng.
    • parseTime

      public static TimeUtils.SeekTime parseTime(String args)
      [EN] Parses a seek time string into milliseconds and determines if it's relative.
      Supports "colon time" (e.g., 1:20:30) or "unit time" (e.g., 1h20m).
      Also detects relative seeking (starting with + or -).

      [VN] Phân tích chuỗi thời gian thành mili giây và xác định xem đó có phải là thời gian tương đối không.
      Hỗ trợ "colon time" (vd: 1:20:30) hoặc "unit time" (vd: 1h20m).
      Cũng phát hiện việc tua tương đối (bắt đầu bằng + hoặc -).
      Parameters:
      args - [EN] The time string to parse.
      [VN] Chuỗi thời gian cần phân tích.
      Returns:
      [EN] A TimeUtils.SeekTime object containing milliseconds and relative flag, or null if parsing failed.
      [VN] Đối tượng TimeUtils.SeekTime chứa số mili giây và cờ tương đối, hoặc null nếu phân tích thất bại.
    • parseColonTime

      public static long parseColonTime(String timestamp)
      [EN] Parses a timestamp formatted with colons.
      Format accepted: HH:MM:SS, MM:SS, or SS.

      [VN] Phân tích chuỗi thời gian được định dạng bằng dấu hai chấm.
      Các định dạng chấp nhận: HH:MM:SS, MM:SS, hoặc SS.
      Parameters:
      timestamp - [EN] Timestamp string (e.g., "1:30:00").
      [VN] Chuỗi thời gian (vd: "1:30:00").
      Returns:
      [EN] Time in milliseconds, or -1 if format is invalid.
      [VN] Thời gian tính bằng mili giây, hoặc -1 nếu định dạng không hợp lệ.
    • parseUnitTime

      public static long parseUnitTime(String timestr)
      [EN] Parses a time string formatted with units.
      Examples: 20m10s, 1d5h, 1h and 20m.

      [VN] Phân tích chuỗi thời gian được định dạng kèm đơn vị.
      Ví dụ: 20m10s, 1d5h, 1h and 20m.
      Parameters:
      timestr - [EN] The unit time string.
      [VN] Chuỗi thời gian kèm đơn vị.
      Returns:
      [EN] Time in milliseconds, or -1 if parsing fails.
      [VN] Thời gian tính bằng mili giây, hoặc -1 nếu phân tích thất bại.