binarySeconds only works for xs:dateTime elements, which means that the
resulting infoset will also have a day/month/year/hour/minute/second
parts. There's no way around that. Note that the dfdl:calendarPattern
does not describe the format of the infoset, but is used to describe the
format of input calendar textual data. The infoset will always be
YYYY-mm-dd hh:mm:ss.

If you wanted only the year, you would need to parse the field as a full
dateTime, and then use inputValueCalc to extract just the year. For example:

  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="dateTime" type="xs:dateTime"
          dfdl:lengthKind="explicit"
          dfdl:lengthUnits="bytes"
          dfdl:length="4"
          dfdl:binaryCalendarRep="binarySeconds"
          dfdl:binaryCalendarEpoch="1970-01-01T00:00:00" />
        <xs:element name="year" type="xs:int"
          dfdl:inputValueCalc="{ fn:year-from-dateTime(../dateTime) }" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>



On 10/1/19 8:38 AM, Costello, Roger L. wrote:
> Hello DFDL community,
> 
> My binary input file contains the number of seconds since epoch for the start 
> of a year.
> 
> For example, the number of seconds since epoch for the start of 1998 is: 
> 883612800
> 
> I want the XML to just show the year (not month, day, and time).
> 
> For example, I want the XML to show this:
> 
> <Date>1998</Date>
> 
> I thought this would do the job:
> 
> <xs:element name="Date" type="xs:dateTime"
>     dfdl:lengthKind="explicit" 
>     dfdl:length="4" 
>     dfdl:binaryCalendarRep="binarySeconds" 
>     dfdl:calendarPattern="yyyy" 
>     dfdl:calendarPatternKind="explicit"
>     dfdl:lengthUnits="bytes" 
>     dfdl:binaryCalendarEpoch="1970-01-01T00:00:00" />
> 
> But apparently that's not correct.
> 
> What is the correct way to do it, please?
> 
> /Roger 
> 

Reply via email to