Julia: conversion between different time periods -


full disclosure: i've been using julia day, may ask questions.

i'm not understanding utility of dates module's period types. let's had 2 times , wanted find number of minutes between them. seems natural thing subtract times , convert result minutes. can deal not having minute constructor (which seems natural python-addled brain), seems convert should able something.

the "solution" of converting millisecond int minute seems little gross. what's better/right/idiomatic way of doing this? (i did rtfm, maybe answer there , missed it.)

y, m, d = (2015, 03, 16) hr1, min1, sec1 = (8, 14, 00) hr2, min2, sec2 = (9, 23, 00) t1 = datetime(y, m, d, hr1, min1, sec1) t2 = datetime(y, m, d, hr2, min2, sec2) # println(t2 - t1)  # 4140000 milliseconds # minute(t2 - t1)  # error: argumenterror("can't convert millisecond minute") # minute(t2 - t1)  # error: `minute` has no method matching                    # minute(::millisecond) # convert(minute, (t2-t1))  # error: `convert` has no method matching                             # convert(::type{minute}, ::millisecond)  delta_t_ms = convert(int, t2 - t1)  function ms_to_min(time_ms)     ms_per_s = 1000     s_per_min = 60     # recall division floating point unless use div function     return div(time_ms, (ms_per_s * s_per_min)) end  delta_t_min = ms_to_min(delta_t_ms) println(minute(delta_t_min))  # 69 minutes 

(my apologies choosing snicker-inducing time interval. happened convert 2 friends' birthdays hours , minutes without thinking it.)

good question; seems should add it! (disclosure: made dates module).

for real, had conversions in there @ 1 point, reason or taken out (i think revolved around whether inexact conversions should throw errors or not, has been cleaned quite bit in base ints/floats). think makes sense add them in. have handful in there other operations, they're useful.

as always, it's matter of has time code/test/submit , that's driven people real needs functionfeel free submit pr if you're feeling ambitious!


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -