Get_iterator.rst 973 B

12345678910111213141516171819202122232425262728293031323334353637
  1. Get an iterator
  2. ------------------------
  3. :Sample Code 1:
  4. .. code:: python
  5. import datetime
  6. from datetimerange import DateTimeRange
  7. time_range = DateTimeRange("2015-01-01T00:00:00+0900", "2015-01-04T00:00:00+0900")
  8. for value in time_range.range(datetime.timedelta(days=1)):
  9. print(value)
  10. :Output 1:
  11. ::
  12. 2015-01-01 00:00:00+09:00
  13. 2015-01-02 00:00:00+09:00
  14. 2015-01-03 00:00:00+09:00
  15. 2015-01-04 00:00:00+09:00
  16. :Sample Code 2:
  17. .. code:: python
  18. from datetimerange import DateTimeRange
  19. from dateutil.relativedelta import relativedelta
  20. time_range = DateTimeRange("2015-01-01T00:00:00+0900", "2016-01-01T00:00:00+0900")
  21. for value in time_range.range(relativedelta(months=+4)):
  22. print(value)
  23. :Output 2:
  24. ::
  25. 2015-01-01 00:00:00+09:00
  26. 2015-05-01 00:00:00+09:00
  27. 2015-09-01 00:00:00+09:00
  28. 2016-01-01 00:00:00+09:00