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

Commit

Permalink
Hotfix #1: Handle formatting of partial dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSputnik committed May 9, 2015
1 parent f54a747 commit d0d1f43
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bbschema/entity_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ def parse_date_string(date_string):
return None


def format_date(date, precision):
if precision == 'YEAR':
return '{}'.format(date.year)
elif precision == 'MONTH':
return '{}-{}'.format(date.year, date.month)
else:
return '{}-{}-{}'.format(date.year, date.month, date.day)

class CreatorCredit(Base):
__tablename__ = 'creator_credit'
__table_args__ = {'schema': 'bookbrainz'}
Expand Down Expand Up @@ -315,10 +323,20 @@ class CreatorData(EntityData):
begin_date_precision = Column(
Enum('YEAR', 'MONTH', 'DAY', name='date_precision')
)

@property
def begin(self):
return format_date(self.begin_date, self.begin_date_precision)

end_date = Column(Date)
end_date_precision = Column(
Enum('YEAR', 'MONTH', 'DAY', name='date_precision')
)

@property
def end(self):
return format_date(self.end_date, self.end_date_precision)

ended = Column(Boolean, server_default='false')

country_id = Column(Integer)
Expand Down Expand Up @@ -434,10 +452,20 @@ class PublisherData(EntityData):
begin_date_precision = Column(
Enum('YEAR', 'MONTH', 'DAY', name='date_precision')
)

@property
def begin(self):
return format_date(self.begin_date, self.begin_date_precision)

end_date = Column(Date)
end_date_precision = Column(
Enum('YEAR', 'MONTH', 'DAY', name='date_precision')
)

@property
def end(self):
return format_date(self.end_date, self.end_date_precision)

ended = Column(Boolean, server_default='false')

country_id = Column(Integer)
Expand Down Expand Up @@ -556,6 +584,10 @@ class EditionData(EntityData):
Enum('YEAR', 'MONTH', 'DAY', name='date_precision')
)

@property
def release(self):
return format_date(self.release_date, self.release_date_precision)

# TODO: add script ID, when that's replicated from MB

country_id = Column(Integer)
Expand Down

0 comments on commit d0d1f43

Please sign in to comment.