-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotationPeriod.m
87 lines (57 loc) · 2.05 KB
/
RotationPeriod.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
classdef RotationPeriod
% Enumeration of log file rotation periods
% This class enumerates log file rotation periods
%
% Syntax:
% mlog.RotationPeriod.<MEMBER>
%
% Copyright 2018-2022 The MathWorks Inc.
%% Enumerations
enumeration
% Always keep the same log file name
none ("")
% New log file with date/time stamp on new instantiation only
instance ("yyyymmdd_HHMMSS")
% New log file each minute
minute ("yyyymmdd_HHMM")
% New log file each hour
hour ("yyyymmdd_HH")
% New log file each day
day ("yyyymmdd")
% New log file each month
month ("yyyymm")
end %enumeration
%% Properties
properties
DateFormat (1,1) string
end
%% Constructor
methods
function obj = RotationPeriod(format)
obj.DateFormat = format;
end
end
%% Methods
methods
function p = getNextPeriod(obj, curTime)
arguments
obj (1,1)
curTime (1,1) datetime = datetime("now","TimeZone","local")
end
switch obj
case "instance"
p = NaT("TimeZone", curTime.TimeZone);
case "minute"
p = datetime(curTime.Year, curTime.Month, curTime.Day, curTime.Hour, curTime.Minute + 1, 0, "TimeZone", curTime.TimeZone);
case "hour"
p = datetime(curTime.Year, curTime.Month, curTime.Day, curTime.Hour + 1, 0, 0, "TimeZone", curTime.TimeZone);
case "day"
p = datetime(curTime.Year, curTime.Month, curTime.Day + 1, "TimeZone", curTime.TimeZone);
case "month"
p = datetime(curTime.Year, curTime.Month + 1, 1, "TimeZone", curTime.TimeZone);
otherwise
p = NaT("TimeZone", curTime.TimeZone);
end %switch
end
end
end % classdef