Skip to end of metadata
Go to start of metadata

Description

When using the week number mask (WW) with a date/time field, the week number value is not what you expected.

Explanation

This issue could be caused by an unexpected date format.  Loftware uses ISO 8601 format to determine the date.  The ISO standard specifies that week 01 in any given year is the week that contains the first Thursday of the month.  ISO weeks also start on Monday, rather than the common Sunday calendar.  If the expected format differs from ISO 8601, then you will need a customization.

Solution

A custom script can be used to calculate the week number.  This script mimics the week format from ISO 8601.  It can be altered to suit other needs as well.

//Change this field name to match your label.
var fieldName = "out";

//calculate current week number
var now = new Date();
var firstDay = new Date(now.getFullYear(),0,1);
var currWeekNo = Math.ceil((((now - firstDay) / 86400000) + firstDay.getDay()+1)/7);
 
// Prepend a 0 if there is only one digit
if(currWeekNo < 10){
   currWeekNo = "0" + String(currWeekNo);
}

//Mimics WW for the current year, add more date info if necessary
label.fields.field.(@name==fieldName).@data = currWeekNo;

 

Article Number

2015034

Versions

All supported LPS family product versions.

Environment

All supported installation environments.