{
  "id": "average-time",
  "version": "3e19a5e3e6b2",
  "status": "published",
  "name": "Average Time Calculator",
  "question": "What is the average time?",
  "summary": "Averages a list of times: durations such as lap or race times (h:mm:ss or m:ss), or clock times such as bedtimes, even across midnight, with the total, fastest and slowest.",
  "category": "days",
  "subcategory": "time-and-hours",
  "url": "https://www.acalculator.org/days/average-time-calculator",
  "markdown": "https://www.acalculator.org/days/average-time-calculator.md",
  "kind": "function",
  "method": "Durations: convert each to seconds (h × 3,600 + m × 60 + s), add, and divide by the count. Clock times: count each in seconds after the start of day (wrapping past midnight), average, and add the start back.",
  "assumptions": [
    "A duration of one number is seconds, two parts are m:ss, three are h:mm:ss; minutes and seconds after a colon are two digits, 00 to 59.",
    "Clock times are averaged as times after the chosen start of day, so the answer depends on it; a noon start suits bedtimes.",
    "Durations are summed in hundredths of a second; the average is rounded to the hundredth, and a clock-time average to the second."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "kind": {
        "title": "Average",
        "description": "Lengths of time (durations), or times of day on a clock.",
        "type": "string",
        "enum": [
          "durations",
          "clock"
        ]
      },
      "t": {
        "title": "Times",
        "description": "The times to average, separated by commas or spaces.",
        "type": "string",
        "maxLength": 4000
      },
      "start": {
        "title": "Day starts at",
        "description": "Clock times are counted from this time, so times on both sides of midnight average correctly.",
        "type": "string",
        "pattern": "^\\d{2}:\\d{2}(:\\d{2})?$"
      }
    }
  },
  "outputs": {
    "average": {
      "label": "Average",
      "description": "The mean of the times.",
      "format": "text"
    },
    "seconds": {
      "label": "Average in seconds",
      "description": "The mean duration in seconds.",
      "format": "number"
    },
    "total": {
      "label": "Total",
      "description": "All the durations added up, h:mm:ss.",
      "format": "text"
    },
    "count": {
      "label": "Times averaged",
      "description": "How many times were typed.",
      "format": "integer"
    },
    "shortest": {
      "label": "Shortest (or earliest)",
      "description": "The smallest time.",
      "format": "text"
    },
    "longest": {
      "label": "Longest (or latest)",
      "description": "The largest time.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "kind": "durations",
      "t": "5:12, 5:08, 5:20, 5:05",
      "start": "00:00"
    },
    "outputs": {
      "average": "0:05:11.25",
      "seconds": 311.25,
      "total": "0:20:45",
      "count": 4,
      "shortest": "0:05:05",
      "longest": "0:05:20"
    },
    "text": "The average is 0:05:11.25."
  },
  "examples": [
    {
      "given": {
        "kind": "durations",
        "t": "5:12, 5:08, 5:20, 5:05"
      },
      "expect": {
        "average": "0:05:11.25",
        "seconds": 311.25,
        "total": "0:20:45",
        "shortest": "0:05:05",
        "longest": "0:05:20"
      },
      "source": "The Python Standard Library, datetime: timedelta objects (durations add and divide exactly in microseconds), https://docs.python.org/3/library/datetime.html#timedelta-objects (retrieved 2026-10-02); hand calculation in content.mdx: 312 + 308 + 320 + 305 = 1,245 s ÷ 4 = 311.25 s"
    },
    {
      "given": {
        "kind": "durations",
        "t": "1:52:10, 1:48:35, 1:55:02"
      },
      "expect": {
        "average": "1:51:55.67",
        "total": "5:35:47"
      },
      "source": "The Python Standard Library, datetime: timedelta objects (durations add and divide exactly in microseconds), https://docs.python.org/3/library/datetime.html#timedelta-objects (retrieved 2026-10-02); hand calculation in content.mdx: 20,147 s ÷ 3 = 6,715.67 s; Python 3: sum(timedeltas, timedelta())/3"
    },
    {
      "given": {
        "kind": "clock",
        "t": "11:00 PM, 1:00 AM, 11:30 PM",
        "start": "12:00"
      },
      "expect": {
        "average": "11:50 PM",
        "shortest": "11:00 PM",
        "longest": "1:00 AM"
      },
      "source": "The Python Standard Library, datetime: timedelta objects (durations add and divide exactly in microseconds), https://docs.python.org/3/library/datetime.html#timedelta-objects (retrieved 2026-10-02); hand calculation in content.mdx: from noon, 11 h, 13 h and 11.5 h average 11 h 50 min, so 11:50 PM"
    },
    {
      "given": {
        "kind": "clock",
        "t": "8:15, 8:45, 9:10",
        "start": "00:00"
      },
      "expect": {
        "average": "8:43:20 AM"
      },
      "source": "The Python Standard Library, datetime: timedelta objects (durations add and divide exactly in microseconds), https://docs.python.org/3/library/datetime.html#timedelta-objects (retrieved 2026-10-02); hand calculation in content.mdx: (29,700 + 31,500 + 33,000) ÷ 3 = 31,400 s after midnight"
    }
  ],
  "sources": [
    "Python Software Foundation, Python 3 documentation, datetime: timedelta objects (sums and division of durations, used as the check for the worked examples). https://docs.python.org/3/library/datetime.html#timedelta-objects (retrieved 2026-10-02)"
  ],
  "related": [
    "time",
    "time-duration",
    "hours",
    "time-to-decimal"
  ],
  "changelog": []
}
