Method Reference: calendarDuration.calweeks

calendarDuration: X = calweeks (calD)

Calendar duration in weeks.

X = calweeks (calD) returns a numeric array with the number of weeks as represented in calD, rounded towards negative infinity, so that -15 days is -3 weeks and not -2.

As for caldays, an array carrying any month at all cannot be stated in weeks and is an error rather than a guess, whatever the sign of that month count. Use split on such an array. A NaN or infinite month count propagates rather than being refused, on the same reasoning as caldays.

calweeks is also available as a function, in which case it performs the opposite conversion.

See also: calendarDuration.calyears, calendarDuration.calquarters, calendarDuration.calmonths, calendarDuration.caldays, calweeks

Source Code: calendarDuration

As a calendarDuration method, calweeks returns the day part of the span as a whole number of weeks.

 d = calendarDuration (0, 0, 40)
d =
  calendarDuration

   40d
 calweeks (d)
ans = 5

Weeks round towards negative infinity, so a negative span rounds away from zero: -15 days is -3 weeks, not -2. As with caldays, a span carrying any month cannot be stated in weeks at all.

 calweeks (calendarDuration (0, 0, [-15, -8, -7, -1, 0, 6, 7, 15]))
ans =

  -3  -2  -1  -1   0   0   1   2