1 //------------------------------------------------------------------------
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) INRIA - Pierre MARECHAL
5 // Copyright (C) 2012 - 2016 - Scilab Enterprises
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
16 //------------------------------------------------------------------------
18 function [Y,M,D,h,m,s] = datevec(N)
23 common_year = [0,31,59,90,120,151,181,212,243,273,304,334,365];
24 leap_year = [0,31,60,91,121,152,182,213,244,274,305,335,366];
27 error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"datevec",1));
31 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real matrix expected.\n"),"datevec",1));
37 common_year = common_year';
38 leap_year = leap_year';
41 // for the moment : hour, minute, second
42 // =========================================================================
44 second = 86400*(N-floor(N));
45 hour = floor(second/3600);
46 second = second - 3600*hour;
47 minute = floor(second/60);
48 second = second - 60*minute;
51 // =========================================================================
54 Year = floor(N/365.2425);
56 temp = N - (365.0*Year + ceil(0.25*Year)- ceil(0.01*Year) + ceil(0.0025*Year));
58 // On retranche 1 si la valeur est inferieur à 0
60 mask = find(temp <= 0);
62 Year(mask) = Year(mask)-1;
64 N(mask) = N(mask) - (365.0*Year(mask) + ceil(0.25*Year(mask)) - ceil(0.01*Year(mask)) + ceil(0.0025*Year(mask)));
65 N(~mask) = temp(~mask);
71 // =========================================================================
75 // construction de la matrice
77 month_day_mat = ones(nr,nc);
78 idx_leap_year = isLeapYear(Year);
80 if ~isempty(Month(idx_leap_year))
81 month_day_mat(idx_leap_year) = leap_year(Month(idx_leap_year)+1);
83 if ~isempty(Month(~idx_leap_year))
84 month_day_mat(~idx_leap_year) = common_year(Month(~idx_leap_year)+1);
87 Month( N>month_day_mat ) = Month( N>month_day_mat )+1;
91 if ~isempty(Month(idx_leap_year))
92 month_day_mat(idx_leap_year) = leap_year(Month(idx_leap_year));
94 if ~isempty(Month(~idx_leap_year))
95 month_day_mat(~idx_leap_year) = common_year(Month(~idx_leap_year));
98 Day = N - month_day_mat;
101 Y(:,1) = matrix(Year ,nr*nc , 1);
102 Y(:,2) = matrix(Month ,nr*nc , 1);
103 Y(:,3) = matrix(Day ,nr*nc , 1);
104 Y(:,4) = matrix(hour ,nr*nc , 1);
105 Y(:,5) = matrix(minute,nr*nc , 1);
106 Y(:,6) = matrix(second,nr*nc , 1);