---
id: 69c5f3d787b1725d5f00c8ba
title: "Challenge 256: Closest Time Direction"
challengeType: 29
dashedName: challenge-256
---

# --description--

Given two times, determine whether you can get from the first to the second faster by moving forward or backward.

- Times are given in 24-hour format (`"HH:MM"`)
- The clock wraps around (23:59 goes to 00:00 when moving forward, and 00:00 goes to 23:59 when moving backwards)

Return:

- `"forward"` if moving forward is shorter
- `"backward"` if moving backward is shorter
- `"equal"` if both directions take the same amount of time

# --hints--

`get_direction("10:00", "12:00")` should return `"forward"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_direction("10:00", "12:00"), "forward")`)
}})
```

`get_direction("11:00", "05:00")` should return `"backward"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_direction("11:00", "05:00"), "backward")`)
}})
```

`get_direction("00:00", "12:00")` should return `"equal"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_direction("00:00", "12:00"), "equal")`)
}})
```

`get_direction("15:45", "01:10")` should return `"forward"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_direction("15:45", "01:10"), "forward")`)
}})
```

`get_direction("03:30", "19:50")` should return `"backward"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_direction("03:30", "19:50"), "backward")`)
}})
```

`get_direction("06:30", "18:30")` should return `"equal"`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_direction("06:30", "18:30"), "equal")`)
}})
```

# --seed--

## --seed-contents--

```py
def get_direction(time1, time2):

    return time1
```

# --solutions--

```py
def get_direction(time1, time2):
    def to_minutes(t):
        h, m = map(int, t.split(':'))
        return h * 60 + m

    start = to_minutes(time1)
    end = to_minutes(time2)
    forward = (end - start + 1440) % 1440
    backward = (start - end + 1440) % 1440

    if forward < backward:
        return 'forward'
    if backward < forward:
        return 'backward'
    return 'equal'
```
