File: datevec.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (73 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download
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
//------------------------------------------------------------------------
// Allan CORNET
// INRIA 2004
//
// Modified by Pierre MARECHAL
// Scilab team
// Copyright INRIA 
// Date : 28 Dec 2005
//------------------------------------------------------------------------

function [Y,M,D,h,m,s] = datevec(varargin)

	lhs=argn(1);   
	rhs=argn(2);
	
	normal_year = [0,31,59,90,120,151,181,212,243,273,304,334,365];
	bissextile_year = [0,31,60,91,121,152,182,213,244,274,305,335,366];
	
	if (rhs==1) & (size(varargin(1)) == [1,1]) then
		ValDate=varargin(1);
		Y = 0;
		M = ones(size(Y));
		D = ones(size(Y));
		
		// Get the year
		
		if ValDate == floor(ValDate) then
			h = 0; 
			m = 0;
			s = 0;
		else
			s = 86400*(ValDate-floor(ValDate));
			h = floor(s/3600);
			s = s - 3600*h;
			m = floor(s/60);
			s = s - 60*m;
		end
		
		ValDate = floor(ValDate);
		Y = floor(ValDate/365.2425);
		
		temp = ValDate - (365.0*Y + ceil(0.25*Y)- ceil(0.01*Y) + ceil(0.0025*Y));
		
		if  temp <= 0 then
			Y = Y - 1;
			ValDate = ValDate - (365.0*Y + ceil(0.25*Y) - ceil(0.01*Y) + ceil(0.0025*Y));
		else
			ValDate = temp;
		end
		
		M = int (ValDate/29.);
		
		if isLeapYear(Y) then
			if ValDate > bissextile_year(M+1) then
				M = M+1;
			end
			D = ValDate - bissextile_year(M);
		else
			if ValDate > normal_year(M+1) then
				M = M+1;
			end
			D = ValDate - normal_year(M);
		end
		
		if (lhs==1) then
			Y=[Y,M,D,h,m,s];
		end
	
	else
		error('parameter incorrect.');
	end

endfunction