Statistics

Problem Statement for "ForumPostMedium"

Problem Statement

In this problem we are using 24-hour time. That is, the first second of each day is 00:00:00 and the last second of each day is 23:59:59.

You are given the String currentTime that contains the current time of day in the above format.

You are writing the software for an online forum. Whenever the software displays a post that has been made strictly less than 24 hours ago, it produces a human-readable message stating when the post was made. There are three types of messages:

  • "few seconds ago", which means the post is made between 0 and 59 seconds ago, inclusive.
  • "X minutes ago", where X is an integer between 1 and 59, inclusive, which means the post is made between X minutes and X minutes 59 seconds ago, inclusive.
  • "X hours ago", where X is an integer between 1 and 23, inclusive, which means the post is made between X hours and X hours 59 minutes 59 seconds ago, inclusive.

In addition to the current time, you are also given the String exactPostTime: the time of day when a post was made. We assume that the post was made strictly less than 24 hours before the time given in currentTime. Calculate and return the appropriate String that describes how long ago the post was made.

Definition

Class:
ForumPostMedium
Method:
getShownPostTime
Parameters:
String, String
Returns:
String
Method signature:
String getShownPostTime(String currentTime, String exactPostTime)
(be sure your method is public)

Constraints

  • currentTime and exactPostTime are each formatted as "HH:MM:SS" (quotes added for clarity) where HH is a two-digit integer between 00 and 23, inclusive, and both MM and SS are two-digit integers between 00 and 59, inclusive. Note that HH, MM, and SS must each have exactly two digits.

Examples

  1. "12:12:12"

    "12:12:12"

    Returns: "few seconds ago"

  2. "12:12:12"

    "12:11:13"

    Returns: "few seconds ago"

  3. "12:12:12"

    "12:11:12"

    Returns: "1 minutes ago"

  4. "12:12:12"

    "11:12:12"

    Returns: "1 hours ago"

    Note that we do not make any special cases to make the messages grammatically correct. For example, if the number of hours is 1, we still return "1 hours" and not "1 hour".

  5. "12:12:12"

    "11:12:13"

    Returns: "59 minutes ago"

  6. "12:12:12"

    "12:12:13"

    Returns: "23 hours ago"

    The post was made 23 hours, 59 minutes and 59 seconds ago (on 12:12:13 on the previous day). According to the rules in the statement, the corresponding human-readable string is "23 hours ago".

  7. "13:00:43"

    "13:00:33"

    Returns: "few seconds ago"

  8. "22:57:33"

    "22:56:58"

    Returns: "few seconds ago"

  9. "16:57:48"

    "16:57:39"

    Returns: "few seconds ago"

  10. "02:21:08"

    "02:20:20"

    Returns: "few seconds ago"

  11. "07:43:24"

    "07:42:34"

    Returns: "few seconds ago"

  12. "17:29:09"

    "17:28:44"

    Returns: "few seconds ago"

  13. "12:28:11"

    "12:27:36"

    Returns: "few seconds ago"

  14. "00:56:34"

    "00:55:45"

    Returns: "few seconds ago"

  15. "02:48:36"

    "02:48:10"

    Returns: "few seconds ago"

  16. "00:41:59"

    "00:41:54"

    Returns: "few seconds ago"

  17. "07:02:53"

    "07:00:57"

    Returns: "1 minutes ago"

  18. "09:39:31"

    "08:53:27"

    Returns: "46 minutes ago"

  19. "20:25:45"

    "20:00:17"

    Returns: "25 minutes ago"

  20. "22:45:49"

    "22:06:41"

    Returns: "39 minutes ago"

  21. "14:28:46"

    "14:08:54"

    Returns: "19 minutes ago"

  22. "06:44:20"

    "06:11:34"

    Returns: "32 minutes ago"

  23. "21:07:53"

    "20:54:41"

    Returns: "13 minutes ago"

  24. "18:40:42"

    "17:52:23"

    Returns: "48 minutes ago"

  25. "14:39:25"

    "14:18:37"

    Returns: "20 minutes ago"

  26. "12:40:02"

    "12:38:44"

    Returns: "1 minutes ago"

  27. "23:19:44"

    "00:16:37"

    Returns: "23 hours ago"

  28. "07:57:13"

    "13:23:22"

    Returns: "18 hours ago"

  29. "18:43:34"

    "07:05:40"

    Returns: "11 hours ago"

  30. "13:07:48"

    "11:39:35"

    Returns: "1 hours ago"

  31. "04:29:55"

    "04:59:27"

    Returns: "23 hours ago"

  32. "09:59:45"

    "17:32:29"

    Returns: "16 hours ago"

  33. "14:02:56"

    "16:22:03"

    Returns: "21 hours ago"

  34. "23:44:44"

    "19:27:11"

    Returns: "4 hours ago"

  35. "17:06:55"

    "23:59:55"

    Returns: "17 hours ago"

  36. "01:15:28"

    "19:36:43"

    Returns: "5 hours ago"

  37. "01:00:00"

    "20:12:12"

    Returns: "4 hours ago"

  38. "00:00:00"

    "00:00:00"

    Returns: "few seconds ago"

  39. "00:00:59"

    "23:59:38"

    Returns: "1 minutes ago"

  40. "12:12:12"

    "13:12:13"

    Returns: "22 hours ago"

  41. "01:00:00"

    "05:00:00"

    Returns: "20 hours ago"

  42. "12:12:12"

    "16:16:16"

    Returns: "19 hours ago"

  43. "00:00:00"

    "20:59:59"

    Returns: "3 hours ago"

  44. "00:00:00"

    "23:59:00"

    Returns: "1 minutes ago"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: