Jump to content
We've recently updated our Privacy Statement, available here ×
  • Fixing incorrect dates display in the end of the year for Studio reports


    prusyn
    • Features: Reports Version: v7.5 Product: Jaspersoft® Studio

    Issue:

    [toc on_off::hide=1]

    Customer is using JasperServer and facing an issue with date fields. If they feed the jrxml with date like 31 Dec-2019, the report generated by jasperreports shows the same date as 31 Dec-2020. The issue of advancing the year by 1 happens only if date is 31 and month is Dec.

     

    Below is the snippet from the jrxml file for a report which produces this error.

    <jr:column width="140" uuid="3eb47b2b-9fb1-4c97-afdb-c0ca1d2f0a37">
       <jr:columnHeader height="36">
           <staticText>
               <reportElement style="th" x="0" y="0" width="140" height="36" 
                              uuid="ca7ec5e5-5c56-4bc9-849d-6bdb1ef5bc0d"/>
               <text>
                  <![CDATA[Original due date]]>
               </text>
           </staticText>
       </jr:columnHeader>
       <jr:detailCell height="30">
          <textField isStretchWithOverflow="true">
             <reportElement style="td" stretchType="RelativeToBandHeight"
                            x="0" y="0" width="140" height="30"
                            uuid="e1bb822a-7cc1-4813-b41d-11e84c935382"/>
             <textFieldExpression>
                <![CDATA[$F{originalDueDate}]]>
             </textFieldExpression>
             <patternExpression>
                <![CDATA["dd MMM YYYY"]]>
             </patternExpression>
          </textField>
       </jr:detailCell>
    </jr:column>

    Resolution:

    The error comes from pattern expression you use. When you are formatting dates in Java there is a subtle difference between YYYY and yyyy. They both represent a year but yyyy represents the calendar year while YYYY represents the year of the week. That’s a subtle difference that only causes problems around a year change so your code could have been running perfectly fine all year only to cause a problem in the new year.

     

    To solve this, use yyyy instead of YYYY in pattern expression:

    <patternExpression>
       <![CDATA["dd MMM yyyy"]]>
    </patternExpression>

     


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...