comparison main/time/weekday.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children 4d5773ef926a
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 2000 Paul Kienzle
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {V =} datevec(date)
19 ## @deftypefnx {Function File} {[Y,M,D,h,m,s] =} datevec(date)
20 ## Breaks the number of days since Jan 1, 0000 into a year-month-day
21 ## hour-minute-second format. By this reckoning, Jan 1, 1970 is day
22 ## number 719529. The fractional portion of @code{date} corresponds to the
23 ## portion of the given day. If a single return value is requested,
24 ## then the components of the date are columns of the matrix @code{V}.
25 ##
26 ## Note: 32-bit architectures only handle times between Dec 14, 1901
27 ## and Jan 19, 2038, with special handling for 0000-01-01. datenum
28 ## returns -1 in case of a range error.
29 ##
30 ## The parameter @code{P} is needed to convert date strings with 2 digit
31 ## years into dates with 4 digit years. 2 digit years are assumed to be
32 ## between @code{P} and @code{P+99}. If @code{P} is not given then the
33 ## current year - 50 is used, so that dates are centered on the present.
34 ## For birthdates, you would want @code{P} to be current year - 99. For
35 ## appointments, you would want @code{P} to be current year.
36 ##
37 ## Dates must be represented as mm/dd/yy or dd-mmm-yyyy. Times must
38 ## be hh:mm:ss or hh:mm:ss PM, with seconds optional. These correspond
39 ## to datestr format codes 0, 1, 2, 3, 13, 14, 15, 16.
40 ##
41 ## @seealso{date,clock,now,datestr,datenum,calendar,weekday}
42 ## @end deftypefn
43
44 function [d,s] = weekday(date,P)
45 if (nargin < 1 || nargin > 2)
46 usage("d = weekday(date [, P])");
47 endif
48 if isstr(date)
49 if nargin < 2, P = []; endif
50 date = datenum(date, P);
51 endif
52 d = rem(floor(date)+5,7)+1;
53 if nargout == 2,
54 global __day_names = ["Sun";"Mon";"Tue";"Wed";"Thu";"Fri";"Sat"];
55 s = __day_names(d,:);
56 endif
57 endfunction