# Path: smart/lib/iso8601.py
# ISO8601_REGEX = re.compile(r"(?P<year>[0-9]{4})(-(?P<month>[0-9]{1,2})(-(?P<day>[0-9]{1,2})"
#     r"((?P<separator>.)(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?"
#     r"(?P<timezone>Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"
# )
# TIMEZONE_REGEX = re.compile("(?P<prefix>[+-])(?P<hours>[0-9]{2}).(?P<minutes>[0-9]{2})")
# ZERO = timedelta(0)
# UTC = Utc()
# class ParseError(Exception):
# class Utc(tzinfo):
# class FixedOffset(tzinfo):
#     def utcoffset(self, dt):
#     def tzname(self, dt):
#     def dst(self, dt):
#     def __init__(self, offset_hours, offset_minutes, name):
#     def utcoffset(self, dt):
#     def tzname(self, dt):
#     def dst(self, dt):
#     def __repr__(self):
# def parse_timezone(tzstring, default_timezone=UTC):
# def parse_date(datestring, default_timezone=UTC):


import time
from django import template
from django.http import HttpResponse
from django.template import Context, loader
from django.template.defaultfilters import stringfilter
from smart.lib import iso8601
# from smart.models import Document

register = template.Library()

@register.filter
@stringfilter
def check_empty(value):
  if value == 'None' or value == '':
    return ''
  else:
    return value
check_empty.is_safe = True


@register.filter
@stringfilter
def get_doc_obj(doc_id):
  try:
    return loader.get_template('document.xml').render(Context({'doc': Document.objects.get(id=doc_id)}))
  except:
    return ""
get_doc_obj.is_safe = True

@register.filter
@stringfilter
def format_iso8601(timestamp):
  if timestamp and not timestamp == 'None':
    if timestamp.find('.') > 0:
      return iso8601.parse_date(timestamp[0:timestamp.find('.')]).isoformat()

# Path: smart/lib/iso8601.py
# ISO8601_REGEX = re.compile(r"(?P<year>[0-9]{4})(-(?P<month>[0-9]{1,2})(-(?P<day>[0-9]{1,2})"
#     r"((?P<separator>.)(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2})(:(?P<second>[0-9]{2})(\.(?P<fraction>[0-9]+))?)?"
#     r"(?P<timezone>Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"
# )
# TIMEZONE_REGEX = re.compile("(?P<prefix>[+-])(?P<hours>[0-9]{2}).(?P<minutes>[0-9]{2})")
# ZERO = timedelta(0)
# UTC = Utc()
# class ParseError(Exception):
# class Utc(tzinfo):
# class FixedOffset(tzinfo):
#     def utcoffset(self, dt):
#     def tzname(self, dt):
#     def dst(self, dt):
#     def __init__(self, offset_hours, offset_minutes, name):
#     def utcoffset(self, dt):
#     def tzname(self, dt):
#     def dst(self, dt):
#     def __repr__(self):
# def parse_timezone(tzstring, default_timezone=UTC):
# def parse_date(datestring, default_timezone=UTC):


# Path: smart/templatetags/template_utils.py
import time
from django import template
from django.http import HttpResponse
from django.template import Context, loader
from django.template.defaultfilters import stringfilter
from smart.lib import iso8601

# from smart.models import Document

register = template.Library()

@register.filter
@stringfilter
def check_empty(value):
  if value == 'None' or value == '':
    return ''
  else:
    return value
check_empty.is_safe = True


@register.filter
@stringfilter
def get_doc_obj(doc_id):
  try:
    return loader.get_template('document.xml').render(Context({'doc': Document.objects.get(id=doc_id)}))
  except:
    return ""
get_doc_obj.is_safe = True

@register.filter
@stringfilter
def format_iso8601(timestamp):
  if timestamp and not timestamp == 'None':
    if timestamp.find('.') > 0:
      return iso8601.parse_date(timestamp[0:timestamp.find('.')]).isoformat()

    return iso8601.parse_date(timestamp).isoformat()