Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Hardcode quarter start to October
Browse files Browse the repository at this point in the history
  • Loading branch information
phss committed Dec 4, 2013
1 parent 4e65c8c commit 304d599
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions backdrop/core/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,25 @@ def start(self, timestamp):
def valid_start_at(self, timestamp):
return timestamp.day == 1


class Quarter(Period):
def __init__(self):
self.name = "month"
self._delta = relativedelta(months=3)

def start(self, timestamp):
return timestamp.replace(month=10, day=1, hour=0, minute=0,
second=0, microsecond=0)

def valid_start_at(self, timestamp):
return False


HOUR = Hour()
DAY = Day()
WEEK = Week()
MONTH = Month()
QUARTER = Quarter()
PERIODS = [HOUR, DAY, WEEK, MONTH]


Expand Down
10 changes: 9 additions & 1 deletion tests/core/test_timeseries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase
import datetime
from hamcrest import assert_that, is_, contains
from backdrop.core.timeseries import timeseries, WEEK, MONTH, DAY, HOUR
from backdrop.core.timeseries import timeseries, WEEK, MONTH, DAY, HOUR, QUARTER
from tests.support.test_helpers import d, d_tz


Expand Down Expand Up @@ -291,3 +291,11 @@ def test_that_a_range_of_five_hours_gives_us_five_data_points(self):
(d_tz(2013, 4, 3, 15), d_tz(2013, 4, 3, 16)),
(d_tz(2013, 4, 3, 16), d_tz(2013, 4, 3, 17))
))

class TestQuarter(TestCase):
def test_that_returns_the_beginning_of_the_current_quarter(self):
some_datetime = d(2013, 12, 4, 10, 23, 43)

start = QUARTER.start(some_datetime)

assert_that(start, is_(d(2013, 10, 1, 0, 0, 0)))

0 comments on commit 304d599

Please sign in to comment.