def _get_end_of_period(val):
    """
    Gets the end of period date (dei:DocumentPeriodEndDate).  Returns the fact value or the context end date on the fact, whichever is later,
    in a tuple with the fact itself and a string representation of the date. The tuple is in a dict keyed off of any LegalEntityAxis members.
    The end of period string is adjusted for viewing to represent the day as expected.  In other words, dates that end in 24:00 will be put at 00:00 of the expected day.

    @return A dictionary of tuples containing the fact, found date and a string representation of that date, keyed off of the LegalEntityAxis members in the format {lea_member: (fact, found_date, date_str)}
    """
    results = {}
    end_of_period_concepts = [c for c in val.modelXbrl.nameConcepts['DocumentPeriodEndDate'] if c.qname.namespaceURI in val.disclosureSystem.standardTaxonomiesDict]
    if len(end_of_period_concepts) == 1:
        end_of_period_dict = facts.LegalEntityAxis_facts_by_member(val.modelXbrl.factsByQname[end_of_period_concepts[0].qname])
        for lea_member, end_of_period_facts in end_of_period_dict.items():
            for fact in end_of_period_facts:
                eop_date = fact.xValue
                # Get maximum of fact value and fact's context end date
                if fact.context is not None:
                    eop_context_end = fact.context.endDatetime
                    date_str = dateunionValue(eop_context_end, subtractOneDay=True)
                    if eop_context_end is not None and (eop_date is None or eop_context_end > eop_date):
                        eop_date = eop_context_end
                        # end dates have a time of 24:00 so adjust them back 1 day
                        date_str = dateunionValue(eop_date, subtractOneDay=True)
                    if lea_member in results:
                        if results[lea_member][1] < eop_date:
                            results[lea_member] = (fact, eop_date, date_str)
                    else:
                        results[lea_member] = (fact, eop_date, date_str)
    return results
Example #2
0
 def oimPeriodValue(cntx):
     if cntx.isForeverPeriod:
         return "forever"
     elif cntx.isStartEndPeriod:
         return "{}/{}".format(dateunionValue(cntx.startDatetime, dateOnlyHour=0), 
                               dateunionValue(cntx.endDatetime, subtractOneDay=True, dateOnlyHour=24))
     else: # instant
         return "PT0S/{}".format(dateunionValue(cntx.endDatetime, subtractOneDay=True, dateOnlyHour=24))
Example #3
0
def _get_end_of_period(val):
    """
    Gets the end of period date (dei:DocumentPeriodEndDate).  Returns the fact
    value or the context end date on the fact, whichever is later, in a tuple
    with the fact itself and a string representation of the date. The tuple is
    in a dict keyed off of any LegalEntityAxis members. The end of period
    string is adjusted for viewing to represent the day as expected.  In other
    words, dates that end in 24:00 will be put at 00:00 of the expected day.

    :param val: bal from which to gather end dates
    :type val: :class:'~arelle.ModelXbrl.ModelXbrl'
    :return: A dictionary of tuples containing the fact, found date and a
        string representation of that date, keyed off of the LegalEntityAxis
        members in the format {lea_member: (fact, found_date, date_str)}
    :rtype: dict
    """
    results = {}
    end_of_period_concepts = [
        c for c in val.modelXbrl.nameConcepts['DocumentPeriodEndDate']
        if c.qname.namespaceURI in val.disclosureSystem.standardTaxonomiesDict
    ]

    if len(end_of_period_concepts) == 1:
        end_of_period_dict = (
            facts.legal_entity_axis_facts_by_member(
                val.modelXbrl.factsByQname[end_of_period_concepts[0].qname]
            )
        )
        for lea_member, end_of_period_facts in end_of_period_dict.items():
            for fact in end_of_period_facts:
                eop_date = fact.xValue
                # Get maximum of fact value and fact's context end date
                if fact.context is not None:
                    eop_context_end = fact.context.endDatetime
                    date_str = (
                        dateunionValue(eop_context_end, subtractOneDay=True)
                    )
                    if ((eop_context_end is not None and
                         (eop_date is None or eop_context_end > eop_date))):
                        eop_date = eop_context_end
                        # end dates have a time of 24:00 so
                        # adjust them back 1 day
                        date_str = (
                            dateunionValue(eop_date, subtractOneDay=True)
                        )
                    if lea_member in results:
                        if results[lea_member][1] < eop_date:
                            results[lea_member] = (fact, eop_date, date_str)
                    else:
                        results[lea_member] = (fact, eop_date, date_str)
    return results
Example #4
0
 def oimPeriodValue(cntx):
     if cntx.isForeverPeriod:
         return "forever"
     elif cntx.isStartEndPeriod:
         return "{}/{}".format(
             dateunionValue(cntx.startDatetime, dateOnlyHour=0),
             dateunionValue(cntx.endDatetime,
                            subtractOneDay=True,
                            dateOnlyHour=24))
     else:  # instant
         return "PT0S/{}".format(
             dateunionValue(cntx.endDatetime,
                            subtractOneDay=True,
                            dateOnlyHour=24))