Repository: sunpy/sunpy

Issue:
get_dates() does not work when under 24hours and spans two days
<!--
We know asking good questions takes effort, and we appreciate your time.
Thank you.

Please be aware that everyone has to follow our code of conduct:
https://github.com/sunpy/sunpy/blob/master/CODE_OF_CONDUCT.rst

These comments are hidden when you submit this github issue.

Please have a search on our GitHub repository to see if a similar issue has already been posted.
If a similar issue is closed, have a quick look to see if you are satisfied by the resolution.
If not please go ahead and open an issue!
-->

### Description
<!--

-->
When using the get_dates function spanning two days it should output both of the days that the time intervals spans. However, this function does not work when the time period is under 24 hours.
### Expected vs Actual behavior
<!--
What did you expect to happen.

What actually happened.
Was the output confusing or poorly described?
-->
If I have the following time interval 
starttime_correct = datetime(2020, 1, 1, 12)
endtime_correct = datetime(2020, 1, 2, 13)
then this function should output 2020/01/01 and 2020/01/02, which it does.

However, if I make this below 24 hours like so
starttime_broken = datetime(2020, 1, 1, 12)
endtime_broken = datetime(2020, 1, 2, 11)
then it only returns 2020/01/01.

### Steps to Reproduce
<!--
Please include code that reproduces the issue whenever possible.
The best reproductions are self-contained scripts with minimal dependencies.
-->

```python
In [2]: import sunpy.time
   ...: from datetime import datetime
   ...: #this period is above 24 hours
   ...: starttime_correct = datetime(2020, 1, 1, 12)
   ...: endtime_correct = datetime(2020, 1, 2, 13)
   ...: interval_correct = sunpy.time.TimeRange(starttime_correct, endtime_correct)
   ...: daylist_correct = interval_correct.get_dates()
   ...: 
   ...: #this period is below 24 hours
   ...: starttime_broken = datetime(2020, 1, 1, 12)
   ...: endtime_broken = datetime(2020, 1, 2, 11)
   ...: interval_broken = sunpy.time.TimeRange(starttime_broken, endtime_broken)
   ...: daylist_broken = interval_broken.get_dates()
   ...: 
   ...: print(daylist_correct)
   ...: print(daylist_broken)

[<Time object: scale='utc' format='isot' value=2020-01-01T00:00:00.000>, <Time object: scale='utc' format='isot' value=2020-01-02T00:00:00.000>]
[<Time object: scale='utc' format='isot' value=2020-01-01T00:00:00.000>]
```

### System Details
<!--
We need to know the sunpy version you are using.
We provide a short function (``sunpy.util.system_info()``) that will provide most of the below information.
-->
- SunPy Version: 2.0.1
- Astropy Version: 4.0.1.post1
- Python Version: 3.7.3
- OS information: Windows 10 10.0.18362 (Intel64 Family 6 Model 78 Stepping 3, GenuineIntel)



Discussion:
Mind if I take this issue?

Resolving patch:
diff --git a/sunpy/time/timerange.py b/sunpy/time/timerange.py
--- a/sunpy/time/timerange.py
+++ b/sunpy/time/timerange.py
@@ -405,10 +405,11 @@ def get_dates(self):
         """
         Return all partial days contained within the time range.
         """
+        delta = self.end.to_datetime().date() - self.start.to_datetime().date()
         dates = []
         dates = [
             parse_time(self.start.strftime('%Y-%m-%d')) + TimeDelta(i*u.day)
-            for i in range(int(self.days.value) + 1)
+            for i in range(delta.days + 1)
         ]
         return dates
 


Test patch:
diff --git a/sunpy/time/tests/test_timerange.py b/sunpy/time/tests/test_timerange.py
--- a/sunpy/time/tests/test_timerange.py
+++ b/sunpy/time/tests/test_timerange.py
@@ -1,4 +1,4 @@
-from datetime import timedelta
+from datetime import datetime, timedelta
 
 import pytest
 
@@ -264,3 +264,15 @@ def test_contains(timerange_a):
         assert '2100/1/1'not in timerange
     assert '2014/05/03 12:00' in timerange
     assert '2014/05/05 21:00' in timerange
+
+
+def test_get_dates_daylist_less_24_hours():
+    starttime = datetime(2020, 1, 1, 12)
+    endtime = datetime(2020, 1, 2, 11)
+    interval = sunpy.time.TimeRange(starttime, endtime)
+    daylist = interval.get_dates()
+    day_one = Time("2020-01-01T00:00:00.000")
+    day_two = Time("2020-01-02T00:00:00.000")
+    assert len(daylist) == 2
+    assert daylist[0] == day_one
+    assert daylist[1] == day_two