|
58 | 58 | # Display format (currently unsupported) |
59 | 59 | Format = 'hh:mm:ss' |
60 | 60 | endproperties |
| 61 | + properties (Constant) |
| 62 | + # Size of fixed-size years, as a number of days, including a fractional part. |
| 63 | + # Equal to 365.2425. |
| 64 | + FixedSizeYearDays = 365.2425 |
| 65 | + endproperties |
61 | 66 |
|
62 | 67 | methods (Static) |
63 | 68 | ## -*- texinfo -*- |
|
171 | 176 | ## @end deftypefn |
172 | 177 | function out = years (this) |
173 | 178 | #YEARS Number of fixed-length years equivalent to this. |
174 | | - out = this.days / 365.2425; |
| 179 | + out = this.days / duration.FixedSizeYearDays; |
175 | 180 | endfunction |
176 | 181 |
|
177 | 182 | # Can't have a days() function as well as a days property or it will cause Octave to crash |
|
271 | 276 | s = rem(minutes, 1) * 60; |
272 | 277 | endfunction |
273 | 278 |
|
| 279 | + ## -*- texinfo -*- |
| 280 | + ## @node duration.datevec |
| 281 | + ## @deftypefn {Method} {[@var{dvec}] =} datevec (@var{obj}) |
| 282 | + ## @deftypefnx {Method} {[@var{Y}, @var{M}, @var{D}, @var{H}, @var{MN}, @var{S}] =} datevec (@var{obj}) |
| 283 | + ## |
| 284 | + ## Convert @var{obj} to a datevec whose elements represent the components of |
| 285 | + ## this duration. The components are the year, month, days, hour, minute, and |
| 286 | + ## second quantities of this duration. The years are in terms of fixed size |
| 287 | + ## years that are 365.2425 days long, and days are fixed size 24-hour days. |
| 288 | + ## The fixed size year size can be found in the FixedSizeYearDays constant |
| 289 | + ## class property on the duration class. The month component is always zero, |
| 290 | + ## since months are variable lengths and there is no equivalent fixed size |
| 291 | + ## month. Thus, the days component may be more than 31. |
| 292 | + ## |
| 293 | + ## When nargout is 0 or 1, returns a double array of size n-by-6, where n is |
| 294 | + ## @code{numel(obj)}. When nargout is 2 or more, returns double arrays the |
| 295 | + ## same size as @var{obj}. |
| 296 | + ## |
| 297 | + ## @end deftypefn |
| 298 | + function [out, M, D, H, MN, S] = datevec (this) |
| 299 | + x = this.days; |
| 300 | + x = x / duration.FixedSizeYearDays; |
| 301 | + [Y, x] = deal (fix (x), rem (x, 1)); |
| 302 | + x = x * duration.FixedSizeYearDays; |
| 303 | + M = zeros (size (this)); |
| 304 | + [D, x] = deal (fix (x), rem (x, 1)); |
| 305 | + x = x * 24; |
| 306 | + [H, x] = deal (fix (x), rem (x, 1)); |
| 307 | + x = x * 60; |
| 308 | + [MN, x] = deal (fix (x), rem (x, 1)); |
| 309 | + x = x * 60; |
| 310 | + S = x; |
| 311 | + if nargout < 2 |
| 312 | + out = [Y(:) M(:) D(:) H(:) MN(:) S(:)]; |
| 313 | + else |
| 314 | + out = Y; |
| 315 | + % Other argouts are already in correct format |
| 316 | + endif |
| 317 | + endfunction |
| 318 | + |
274 | 319 | function [keysA, keysB] = proxyKeys (a, b) |
275 | 320 | #PROXYKEYS Proxy key values for sorting and set operations |
276 | 321 | keysA = a.days(:); |
|
0 commit comments