1 //------------------------------------------------------------------------
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2005 - 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 // Maurice Kraitchik Algorithm
17 //------------------------------------------------------------------------
19 function [N,S] = weekday(D,form)
26 if rhs < 1 | rhs > 2 then
27 error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"weekday",1,2));
31 error(msprintf(gettext("%s: Wrong type for input argument #%d: Real constant matrix expected.\n"),"weekday",1));
34 if (rhs==2) & (form <> "long") & (form <> "short") then
35 error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"weekday",2,"long","short"));
40 common_year = [0,31,59,90,120,151,181,212,243,273,304,334,365];
41 leap_year = [0,31,60,91,121,152,182,213,244,274,305,335,366];
42 week_numbers = [7,1,2,3,4,5,6];
44 week_strings_short = [gettext("Sat"), ..
52 week_strings_long = [gettext("Saturday"), ..
53 gettext("Sunday") , ..
54 gettext("Monday") , ..
55 gettext("Tuesday") , ..
56 gettext("Wednesday") , ..
57 gettext("Thursday") , ..
58 gettext("Friday") , ..
63 if form == "long" then
64 week_strings = week_strings_long;
66 week_strings = week_strings_short;
69 week_strings = week_strings_short;
78 common_year = common_year';
79 leap_year = leap_year';
82 month_day_mat = ones(nr,nc);
88 Y = floor(D/365.2425);
89 temp = D - (365.0*Y + ceil(0.25*Y)- ceil(0.01*Y) + ceil(0.0025*Y));
91 mask = find(temp <= 0);
93 Y(mask) = Y(mask) - 1;
94 D(mask) = D(mask) - (365.0*Y(mask) + ceil(0.25*Y(mask)) - ceil(0.01*Y(mask)) + ceil(0.0025*Y(mask)));
95 D(~mask) = temp(~mask);
101 idx_leap_year = isLeapYear(Y);
103 if ~isempty(M(idx_leap_year))
104 month_day_mat(idx_leap_year) = leap_year(M(idx_leap_year)+1);
106 if ~isempty(M(~idx_leap_year))
107 month_day_mat(~idx_leap_year) = common_year(M(~idx_leap_year)+1);
110 M( D>month_day_mat ) = M( D>month_day_mat )+1;
112 if ~isempty(M(idx_leap_year))
113 month_day_mat(idx_leap_year) = leap_year(M(idx_leap_year));
115 if ~isempty(M(~idx_leap_year))
116 month_day_mat(~idx_leap_year) = common_year(M(~idx_leap_year));
119 d = D - month_day_mat;
124 y( M==1 | M==2 ) = Y( M==1 | M==2 ) - 1;
126 m( M<>1 & M<>2 ) = M( M<>1 & M<>2 );
127 y( M<>1 & M<>2 ) = Y( M<>1 & M<>2 );
129 n = modulo( (d + floor(2*m) + floor(3*(m+1)/5) + y + floor(y/4) - floor(y/100) + floor(y/400) + 2) , 7 );
131 N = matrix( week_numbers(n+1) , nr, nc );
132 S = matrix( week_strings(n+1) , nr, nc );