Skip to content

Commit 37ff4d8

Browse files
committed
add duration.hms() method
1 parent 5c1dec2 commit 37ff4d8

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Tablicious Changelog
44
0.4.7 (unreleased)
55
------------------
66

7-
* (nothing here yet)
7+
* Date/time fixes
8+
* Add duration.hms() method.
89

910
0.4.6 (2026-02-16)
1011
------------------

inst/@datetime/datetime.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,9 @@
532532
## @node datetime.hms
533533
## @deftypefn {Method} {[@var{h}, @var{m}, @var{s}] =} hms (@var{obj})
534534
##
535-
## Get the Hour, Minute, and Second components of a @var{obj}.
535+
## Get the Hour, Minute, and Second components of a @var{datetime}. These are the time
536+
## of day components. The Year, Month, and Day components are ignored, and not
537+
## incorporated in to the result.
536538
##
537539
## For zoned @code{datetime}s, these will be local times in the associated time zone.
538540
##

inst/@duration/duration.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,25 @@
252252
out = this.days * (24 * 60 * 60 * 1000);
253253
endfunction
254254

255+
## -*- texinfo -*-
256+
## @node duration.hms
257+
## @deftypefn {Method} {[@var{h}, @var{m}, @var{s}] =} hms (@var{obj})
258+
##
259+
## Get the Hour, Minute, and Second values of a @var{duration}. These are
260+
## the hour, minute, and second values that when combined are equal to the
261+
## same duration value.
262+
##
263+
## Returns double arrays the same size as @code{obj}.
264+
##
265+
## @end deftypefn
266+
function [h, m, s] = hms (this)
267+
hours = this.days * 24;
268+
h = fix(hours);
269+
minutes = rem(hours, 1) * 60;
270+
m = fix(minutes);
271+
s = rem(minutes, 1) * 60;
272+
endfunction
273+
255274
function [keysA, keysB] = proxyKeys (a, b)
256275
#PROXYKEYS Proxy key values for sorting and set operations
257276
keysA = a.days(:);

0 commit comments

Comments
 (0)