Skip to content

Commit

Permalink
Transformation Registry 1, implement missing date transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
Herm Fischer authored and Herm Fischer committed Jun 14, 2015
1 parent 6707e94 commit 832bd02
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions arelle/FunctionIxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def call(xc, p, localname, args):
raise XPathContext.FunctionNotAvailable("xfi:{0}".format(localname))

dateslashPattern = re.compile(r"^\s*(\d+)/(\d+)/(\d+)\s*$")
daymonthslashPattern = re.compile(r"^\s*([0-9]{1,2})/([0-9]{1,2})\s*$")
monthdayslashPattern = re.compile(r"^\s*([0-9]{1,2})/([0-9]{1,2})\s*$")
datedotPattern = re.compile(r"^\s*(\d+)\.(\d+)\.(\d+)\s*$")
daymonthPattern = re.compile(r"^\s*([0-9]{1,2})[^0-9]+([0-9]{1,2})\s*$")
monthdayPattern = re.compile(r"^\s*([0-9]{1,2})[^0-9]+([0-9]{1,2})[A-Za-z]*\s*$")
Expand All @@ -48,6 +50,14 @@ def call(xc, p, localname, args):
monthyearInPattern = re.compile(r"^\s*([^\s0-9\u0966-\u096F]+)\s([0-9\u0966-\u096F]{4})\s*$")
yearmonthEnPattern = re.compile(r"^\s*([0-9]{1,2}|[0-9]{4})[^0-9]+(January|February|March|April|May|June|July|August|September|October|November|December|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER)\s*$")

# TR1-only patterns, only allow space separators, no all-CAPS month name, only 2 or 4 digit years
daymonthShortEnTR1Pattern = re.compile(r"^\s*([0-9]{1,2})\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*$")
monthdayShortEnTR1Pattern = re.compile(r"^\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+([0-9]{1,2})[A-Za-z]{0,2}\s*$")
monthyearShortEnTR1Pattern = re.compile(r"^\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+([0-9]{2}|[0-9]{4})\s*$")
monthyearLongEnTR1Pattern = re.compile(r"^\s*(January|February|March|April|May|June|July|August|September|October|November|December)\s+([0-9]{2}|[0-9]{4})\s*$")
yearmonthShortEnTR1Pattern = re.compile(r"^\s*([0-9]{2}|[0-9]{4})\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*$")
yearmonthLongEnTR1Pattern = re.compile(r"^\s*([0-9]{2}|[0-9]{4})\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s*$")

erayearmonthjpPattern = re.compile("^[\\s\u00A0]*(\u660E\u6CBB|\u660E|\u5927\u6B63|\u5927|\u662D\u548C|\u662D|\u5E73\u6210|\u5E73)[\\s\u00A0]*([0-9]{1,2}|\u5143)[\\s\u00A0]*\u5E74[\\s\u00A0]*([0-9]{1,2})[\\s\u00A0]*\u6708[\\s\u00A0]*$")
erayearmonthdayjpPattern = re.compile("^[\\s\u00A0]*(\u660E\u6CBB|\u660E|\u5927\u6B63|\u5927|\u662D\u548C|\u662D|\u5E73\u6210|\u5E73)[\\s\u00A0]*([0-9]{1,2}|\u5143)[\\s\u00A0]*\u5E74[\\s\u00A0]*([0-9]{1,2})[\\s\u00A0]*\u6708[\\s\u00A0]*([0-9]{1,2})[\\s\u00A0]*\u65E5[\\s\u00A0]*$")
yearmonthcjkPattern = re.compile("^[\\s\u00A0]*([0-9]{4}|[0-9]{1,2})[\\s\u00A0]*\u5E74[\\s\u00A0]*([0-9]{1,2})[\\s\u00A0]*\u6708\\s*$")
Expand Down Expand Up @@ -276,6 +286,22 @@ def datemonthday(arg):
return "--{0}-{1}".format(mo, day)
raise XPathContext.FunctionArgType(1,"xs:gMonthDay")

def datedaymonthSlashTR1(arg):
m = daymonthslashPattern.match(arg)
if m and m.lastindex == 2:
mo = z2(m.group(2))
day = z2(m.group(1))
return "--{0}-{1}".format(mo, day)
raise XPathContext.FunctionArgType(1,"xs:gMonthDay")

def datemonthdaySlashTR1(arg):
m = monthdayslashPattern.match(arg)
if m and m.lastindex == 2:
mo = z2(m.group(1))
day = z2(m.group(2))
return "--{0}-{1}".format(mo, day)
raise XPathContext.FunctionArgType(1,"xs:gMonthDay")

def datedaymonthdk(arg):
m = daymonthDkPattern.match(arg)
if m and m.lastindex == 4:
Expand All @@ -302,6 +328,14 @@ def datedaymonthen(arg):
return "--{0:02}-{1}".format(_mo, _day)
raise XPathContext.FunctionArgType(1,"xs:gMonthDay")

def datedaymonthShortEnTR1(arg):
m = daymonthShortEnTR1Pattern.match(arg)
if m and m.lastindex == 2:
_mo = monthnumber[m.group(2)]
_day = z2(m.group(1))
return "--{0:02}-{1}".format(_mo, _day)
raise XPathContext.FunctionArgType(1,"xs:gMonthDay")

def datemonthdayen(arg):
m = monthdayEnPattern.match(arg)
if m and m.lastindex == 2:
Expand All @@ -311,6 +345,14 @@ def datemonthdayen(arg):
return "--{0:02}-{1}".format(_mo, _day)
raise XPathContext.FunctionArgType(1,"xs:gMonthDay")

def datemonthdayShortEnTR1(arg):
m = monthdayShortEnTR1Pattern.match(arg)
if m and m.lastindex == 2:
_mo = monthnumber[m.group(1)]
_day = z2(m.group(2))
return "--{0:02}-{1}".format(_mo, _day)
raise XPathContext.FunctionArgType(1,"xs:gMonthDay")

def datedaymonthyear(arg):
m = daymonthyearPattern.match(arg)
if m and m.lastindex == 3 and checkDate(yr(m.group(3)), m.group(2), m.group(1)):
Expand Down Expand Up @@ -353,6 +395,18 @@ def datemonthyearen(arg):
return "{0}-{1:02}".format(yr(m.group(2)), monthnumber[m.group(1)])
raise XPathContext.FunctionArgType(1,"xs:gYearMonth")

def datemonthyearShortEnTR1(arg):
m = monthyearShortEnTR1Pattern.match(arg)
if m and m.lastindex == 2:
return "{0}-{1:02}".format(yr(m.group(2)), monthnumber[m.group(1)])
raise XPathContext.FunctionArgType(1,"xs:gYearMonth")

def datemonthyearLongEnTR1(arg):
m = monthyearLongEnTR1Pattern.match(arg)
if m and m.lastindex == 2:
return "{0}-{1:02}".format(yr(m.group(2)), monthnumber[m.group(1)])
raise XPathContext.FunctionArgType(1,"xs:gYearMonth")

def datemonthyearin(arg):
m = monthyearInPattern.match(arg)
try:
Expand All @@ -368,6 +422,18 @@ def dateyearmonthen(arg):
return "{0}-{1:02}".format(yr(m.group(1)), monthnumber[m.group(2)])
raise XPathContext.FunctionArgType(1,"xs:gYearMonth")

def dateyearmonthShortEnTR1(arg):
m = yearmonthShortEnTR1Pattern.match(arg)
if m and m.lastindex == 2:
return "{0}-{1:02}".format(yr(m.group(1)), monthnumber[m.group(2)])
raise XPathContext.FunctionArgType(1,"xs:gYearMonth")

def dateyearmonthLongEnTR1(arg):
m = yearmonthLongEnTR1Pattern.match(arg)
if m and m.lastindex == 2:
return "{0}-{1:02}".format(yr(m.group(1)), monthnumber[m.group(2)])
raise XPathContext.FunctionArgType(1,"xs:gYearMonth")

def datedaymonthyeardk(arg):
m = daymonthyearDkPattern.match(arg)
if m and m.lastindex == 5:
Expand Down Expand Up @@ -543,7 +609,7 @@ def numunitdecimalin(arg):

ixtFunctions = {

# 3010-04-20 functions
# 2010-04-20 functions
'dateslashus': dateslashus,
'dateslasheu': dateslasheu,
'datedotus': datedotus,
Expand All @@ -559,7 +625,15 @@ def numunitdecimalin(arg):
'numspacedot': numspacedot,
'numdotcomma': numdotcomma,
'numcomma': numdotcomma,
'numspacecomma': numspacecomma,
'numspacecomma': numspacecomma,
'dateshortdaymonthuk': datedaymonthShortEnTR1,
'dateshortmonthdayus': datemonthdayShortEnTR1,
'dateslashdaymontheu': datedaymonthSlashTR1,
'dateslashmonthdayus': datemonthdaySlashTR1,
'datelongyearmonth': dateyearmonthLongEnTR1,
'dateshortyearmonth': dateyearmonthShortEnTR1,
'datelongmonthyear': datemonthyearLongEnTR1,
'dateshortmonthyear': datemonthyearShortEnTR1,

# 2011-07-31 functions
'booleanfalse': booleanfalse,
Expand Down

0 comments on commit 832bd02

Please sign in to comment.