Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/correcting date time #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 140 additions & 98 deletions +yaml/DateTime.m
Original file line number Diff line number Diff line change
@@ -1,166 +1,199 @@
classdef DateTime
Copyright (c) 2011
This program is a result of a joined cooperation of Energocentrum
PLUS, s.r.o. and Czech Technical University (CTU) in Prague.
The program is maintained by Energocentrum PLUS, s.r.o. and
licensed under the terms of MIT license. Full text of the license
is included in the program release.
Author(s):
Jiri Cigler, Dept. of Control Engineering, CTU Prague & Automatic Control Laboratory, ETH Zurich
Jan Siroky, Energocentrum PLUS s.r.o.
Implementation and Revisions:
Auth Date Description of change
---- --------- -------------------------------------------------
jc 01-Mar-11 First implementation
jc 30-Sep-11 Added function colon
jc 07-Jan-12 Added functions addtodate,datevec,weekday
% Copyright (c) 2011
% This program is a result of a joined cooperation of Energocentrum
% PLUS, s.r.o. and Czech Technical University (CTU) in Prague.
% The program is maintained by Energocentrum PLUS, s.r.o. and
% licensed under the terms of MIT license. Full text of the license
% is included in the program release.
% Author(s):
% Jiri Cigler, Dept. of Control Engineering, CTU Prague & Automatic Control Laboratory, ETH Zurich
% Jan Siroky, Energocentrum PLUS s.r.o.
% Implementation and Revisions:
% Auth Date Description of change
% ---- --------- -------------------------------------------------
% jc 01-Mar-11 First implementation
% jc 30-Sep-11 Added function colon
% jc 07-Jan-12 Added functions addtodate,datevec,weekday
properties
serialDate
end
methods
import yaml.*;
function this = DateTime(varargin) if numel(varargin)==1 && isa(varargin{1},'java.util.Date')
sec = varargin{1}.getTime/1000;
this.serialDate=datenum(1970,1,1,0,0,sec);
function this = DateTime(varargin)
import yaml.*;
if numel(varargin)==1 && isa(varargin{1},'java.util.Date')
sec = varargin{1}.getTime/1000;
this.serialDate=datenum(1970,1,1,0,0,sec);
else
this.serialDate=datenum(varargin{:});
end
end
import yaml.*;
function this = plus(this,val) o =@plus;
function this = plus(this,val)
import yaml.*;
o =@plus;
this = doFun(this,o,val);
end
import yaml.*;
function this = minus(this,val) o =@minus;
function this = minus(this,val)
import yaml.*;
o =@minus;
this = doFun(this,o,val);
end
import yaml.*;
function this = times(this,val) o =@times;
function this = times(this,val)
import yaml.*;
o =@times;
this = doFun(this,o,val);
end
import yaml.*;
function this = mtimes(this,val) o =@mtimes;
function this = mtimes(this,val)
import yaml.*;
o =@mtimes;
this = doFun(this,o,val);
end
import yaml.*;
function this = mrdivide(this,val) o =@mrdivide;
function this = mrdivide(this,val)
import yaml.*;
o =@mrdivide;
this = doFun(this,o,val);
end
import yaml.*;
function this = rdivide(this,val) o =@rdivide;
function this = rdivide(this,val)
import yaml.*;
o =@rdivide;
this = doFun(this,o,val);
end
import yaml.*;
function this = horzcat(this,varargin) for i=1:numel(varargin)
function this = horzcat(this,varargin)
import yaml.*;
for i=1:numel(varargin)
this.serialDate = [this.serialDate, varargin{i}.serialDate];
end
end
import yaml.*;
function out = colon(this,step,to) vect = [double(this):double(step):double(to)]';
function out = colon(this,step,to)
import yaml.*;
vect = [double(this):double(step):double(to)]';
out =DateTime(vect);
end
import yaml.*;
function this = vertcat(this,varargin) for i=1:numel(varargin)
function this = vertcat(this,varargin)
import yaml.*;
for i=1:numel(varargin)
this.serialDate = [this.serialDate; varargin{i}.serialDate];
end
end
import yaml.*;
function this = ctranspose(this) this.serialDate = this.serialDate';
function this = ctranspose(this)
import yaml.*;
this.serialDate = this.serialDate';
end
import yaml.*;
function this = transpose(this) this.serialDate = this.serialDate';
function this = transpose(this)
import yaml.*;
this.serialDate = this.serialDate';
end
import yaml.*;
function disp(this) disp([this.serialDate])
function disp(this)
import yaml.*;
disp([this.serialDate])
end
import yaml.*;
function out = double(this) out = this.serialDate;
function out = double(this)
import yaml.*;
out = this.serialDate;
end
import yaml.*;
function out = length(this) out = length(this.serialDate);
function out = length(this)
import yaml.*;
out = length(this.serialDate);
end
import yaml.*;
function out = size(this,varargin) out = size(this.serialDate,varargin{:});
function out = size(this,varargin)
import yaml.*;
out = size(this.serialDate,varargin{:});
end
import yaml.*;
function out = numel(this) out = numel(this.serialDate);
function out = numel(this)
import yaml.*;
out = numel(this.serialDate);
end
import yaml.*;
function out = isreal(this) out = isreal(this.serialDate);
function out = isreal(this)
import yaml.*;
out = isreal(this.serialDate);
end
import yaml.*;
function out = isnan(this) out = isnan(this.serialDate);
function out = isnan(this)
import yaml.*;
out = isnan(this.serialDate);
end
import yaml.*;
function out = isfinite(this) out = isfinite(this.serialDate);
function out = isfinite(this)
import yaml.*;
out = isfinite(this.serialDate);
end
import yaml.*;
function out = le(this,B) if isa(B,'DateTime')
function out = le(this,B)
import yaml.*;
if isa(B,'DateTime')
out = le(this.serialDate,B.serialDate);
else
out = le(this.serialDate,B);
end
end
import yaml.*;
function out = lt(this,B) fun=@lt;
function out = lt(this,B)
import yaml.*;
fun=@lt;
if isa(B,'DateTime')
out = fun(this.serialDate,B.serialDate);
else
out = fun(this.serialDate,B);
end
end
import yaml.*;
function out = gt(this,B) fun=@gt;
function out = gt(this,B)
import yaml.*;
fun=@gt;
if isa(B,'DateTime')
out = fun(this.serialDate,B.serialDate);
else
out = fun(this.serialDate,B);
end
end
import yaml.*;
function out = eq(this,B) fun=@eq;
function out = eq(this,B)
import yaml.*;
fun=@eq;
if isa(B,'DateTime')
out = fun(this.serialDate,B.serialDate);
else
out = fun(this.serialDate,B);
end
end
import yaml.*;
function out = diff(this) out = diff(this.serialDate);
function out = diff(this)
import yaml.*;
out = diff(this.serialDate);
end
import yaml.*;
function out = norm(this,varargin) out = norm(this.serialDate,varargin{:});
function out = norm(this,varargin)
import yaml.*;
out = norm(this.serialDate,varargin{:});
end
import yaml.*;
function [this k] = sort(this,varargin) [this.serialDate k] = sort(this.serialDate,varargin{:});
function [this k] = sort(this,varargin)
import yaml.*;
[this.serialDate k] = sort(this.serialDate,varargin{:});
end
import yaml.*;
function this = subsref(this,S) if isa(S.subs{1},'DateTime')
function this = subsref(this,S)
import yaml.*;
if isa(S.subs{1},'DateTime')
S.subs{1}=double(S.subs{1});
end
this.serialDate = subsref(this.serialDate,S);
end
import yaml.*;
function idx = subsindex(this) idx = double(this)-1;
function idx = subsindex(this)
import yaml.*;
idx = double(this)-1;
end
import yaml.*;
function endidx = end(this,k,n) if size(this.serialDate,1)==1 || size(this.serialDate,2)==1
function endidx = end(this,k,n)
import yaml.*;
if size(this.serialDate,1)==1 || size(this.serialDate,2)==1
endidx=numel(this.serialDate);
else
endidx = size(this.serialDate,k);
end
end
import yaml.*;
function this = subsasgn(this, S, B) if not(isa(B,'DateTime'))
function this = subsasgn(this, S, B)
import yaml.*;
if not(isa(B,'DateTime'))
B=DateTime(B);
end
this.serialDate =subsasgn(this.serialDate, S, B);
end
import yaml.*;
function res = bsxfun(fun,A,B) res = fun(A,B);
function res = bsxfun(fun,A,B)
import yaml.*;
res = fun(A,B);
end
import yaml.*;
function out =superiorfloat (x,y,xi) if isa(x,'DateTime') && isa(xi,'DateTime')
function out =superiorfloat (x,y,xi)
import yaml.*;
if isa(x,'DateTime') && isa(xi,'DateTime')
out = superiorfloat(x.serialDate,y,xi.serialDate);
elseif isa(x,'DateTime') && not(isa(xi,'DateTime'))
out = superiorfloat(x.serialDate,y,xi);
Expand All @@ -170,23 +203,29 @@ function disp(this) disp([this.serialDate])
out = superiorfloat(x,y,xi);
end
end
import yaml.*;
function this = floor(this) this.serialDate = floor(this.serialDate);
function this = floor(this)
import yaml.*;
this.serialDate = floor(this.serialDate);
end
import yaml.*;
function this = max(this,varargin) this.serialDate = max(this.serialDate,varargin{:});
function this = max(this,varargin)
import yaml.*;
this.serialDate = max(this.serialDate,varargin{:});
end
import yaml.*;
function this = min(this,varargin) this.serialDate = min(this.serialDate,varargin{:});
function this = min(this,varargin)
import yaml.*;
this.serialDate = min(this.serialDate,varargin{:});
end
import yaml.*;
function out = datestr(this,varargin) out = datestr(this.serialDate,varargin{:});
function out = datestr(this,varargin)
import yaml.*;
out = datestr(this.serialDate,varargin{:});
end
import yaml.*;
function out = addtodate(this,varargin) out = addtodate(this.serialDate,varargin{:});
function out = addtodate(this,varargin)
import yaml.*;
out = addtodate(this.serialDate,varargin{:});
end
import yaml.*;
function varargout= datevec(this,varargin) nout = nargout;
function varargout= datevec(this,varargin)
import yaml.*;
nout = nargout;
if nout <=1
varargout{1} = datevec(this.serialDate,varargin{:});
elseif nout ==2
Expand All @@ -199,11 +238,14 @@ function disp(this) disp([this.serialDate])
[varargout{1} varargout{2} varargout{3} varargout{4} varargout{5} ] = datevec(this.serialDate,varargin{:});
elseif nout ==6
[varargout{1} varargout{2} varargout{3} varargout{4} varargout{5} varargout{6} ] = datevec(this.serialDate,varargin{:});
else
else
error('Unknown function call');
end
end
end
methods (Access = private)
import yaml.*;
function this = doFun (this,o, val)
function this = doFun (this,o, val)
import yaml.*;
end
end
end