Creating new date with sum

I wish to calculate the departure date by subtracting number of transport days from the delivery date. How to do this?

'Delivery Date': number 'date'
'Transport Days': number 'days2'
'Departure Date': number 'date' = sum ( .'Delivery Date' , - .'Transport Days')

'date' in 'days'
	= 'date-time'+ 0 * 10 ^ 0 in 'seconds'
	@date
'days2'
    @numerical-type: (
		label: "days"

state constraint violation for ‘quantity type’. Unexpected state for ‘type’:

application.alan(3536, 39): - expected: ‘quantity’

application.alan(27482, 9): - but found: ‘scale’

application.alan(27482, 9): defined by .‘date’ of type ‘application’.‘numerical types’

equality constraint violation for ‘value’:

application.alan(27482, 2): - expected: .‘date’ of type ‘application’.‘numerical types’

application.alan(27503, 2): - but found: .‘days2’ of type ‘application’.‘numerical types’

You can achieve this by using the addition operator add instead.

A minimal example:

root {
	'Start Date': number 'date'
	'Days': number 'days'
	'End Date': number 'date' = add ( .'Start Date', .'Days' )
}

numerical-types
	'days'
	'date' in 'days' @date
1 Like

To explain a bit more: add can add up two numbers of different numerical types, where the second one should be the quantity unit of the left.

So in the case of dates: you can add a date and a quantity of days. And with date-time, you can add seconds. And with the temperature, you could add a temperature difference in degrees.

It wouldn’t be meaningful to add a date to a date (which would be expected from a ‘sum’)

2 Likes