Skip to content

Commit 9ffedf3

Browse files
author
Enric Sala
committed
Add tests to check the time formatting of the series builder
1 parent 53e3d5c commit 9ffedf3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/SeriesTest.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,37 @@ function skips_nonfinite_samples(test)
200200
exp = 'weather temperature=24.3 1529933525520';
201201
test.verifyEqual(s.toLine(), exp);
202202
end
203+
204+
function time_is_added_in_millis_by_default(test)
205+
millis = 1529933525520;
206+
time = datetime(millis / 1000, 'ConvertFrom', 'posixtime');
207+
s = Series('weather') ...
208+
.fields('temperature', 24.3) ...
209+
.time(time);
210+
exp = 'weather temperature=24.3 1529933525520';
211+
test.verifyEqual(s.toLine(), exp);
212+
end
213+
214+
function time_supports_different_precisions(test)
215+
millis = 1529933525520;
216+
time = datetime(millis / 1000, 'ConvertFrom', 'posixtime');
217+
s = Series('weather') ...
218+
.fields('temperature', 24.3);
219+
precisions = struct( ...
220+
'ns', '1529933525520000000', ...
221+
'u', '1529933525520000', ...
222+
'ms', '1529933525520', ...
223+
's', '1529933526', ...
224+
'm', '25498892', ...
225+
'h', '424982');
226+
names = fieldnames(precisions);
227+
for i = 1:length(names)
228+
name = names{i};
229+
exp = [' ', precisions.(name)];
230+
line = s.time(time).toLine(name);
231+
test.verifyTrue(endsWith(line, exp));
232+
end
233+
end
203234
end
204235

205236
end

0 commit comments

Comments
 (0)