Permalink
Browse files

Date parsing using dateutil

  • Loading branch information...
1 parent c053e04 commit 0da271fa8c5377f0c531183968a1b9f2ceceae5e @dbrgn committed Apr 7, 2013
Showing with 8 additions and 1 deletion.
  1. +1 −0 requirements.pip
  2. +7 −1 shiva/utils.py
View
@@ -7,3 +7,4 @@ pyLast==0.5.11
lxml==3.1beta1
mutagen==1.21
docopt==0.6.1
+python-dateutil==2.1
View
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
import os
import re
+import datetime
from random import random
from hashlib import md5
import translitcodec # don't remove!
import mutagen
+from dateutil import parser as date_parser
PUNCT_RE = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
@@ -103,7 +105,11 @@ def album(self, value):
@property
def release_year(self):
"""The album release year."""
- return self._getter('date')
+ DEFAULT_DATE = datetime.datetime(datetime.MINYEAR, 1, 1)
+ date = date_parser.parse(self._getter('date', ''), default=DEFAULT_DATE).date()
+ if date != DEFAULT_DATE:
+ return date.year
+ return ''
@release_year.setter
def release_year(self, value):

0 comments on commit 0da271f

Please sign in to comment.