Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sdkjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
sdkjs
Commits
76226ab6
Commit
76226ab6
authored
Aug 04, 2017
by
GoshaZotov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separate function weekNumber
parent
5553c680
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
60 deletions
+30
-60
cell/model/FormulaObjects/dateandtimeFunctions.js
cell/model/FormulaObjects/dateandtimeFunctions.js
+30
-60
No files found.
cell/model/FormulaObjects/dateandtimeFunctions.js
View file @
76226ab6
...
...
@@ -410,6 +410,34 @@
return
true
;
}
function
weekNumber
(
dt
,
iso
,
type
)
{
dt
.
setUTCHours
(
0
,
0
,
0
);
var
startOfYear
=
new
Date
(
Date
.
UTC
(
dt
.
getUTCFullYear
(),
0
,
1
));
var
endOfYear
=
new
Date
(
dt
);
endOfYear
.
setUTCMonth
(
11
);
endOfYear
.
setUTCDate
(
31
);
var
wk
=
parseInt
(((
dt
-
startOfYear
)
/
c_msPerDay
+
iso
[
startOfYear
.
getUTCDay
()])
/
7
);
if
(
type
)
{
switch
(
wk
)
{
case
0
:
// Возвращаем номер недели от 31 декабря предыдущего года
startOfYear
.
setUTCDate
(
0
);
return
weekNumber
(
startOfYear
,
iso
,
type
);
case
53
:
// Если 31 декабря выпадает до четверга 1 недели следующего года
if
(
endOfYear
.
getUTCDay
()
<
4
)
{
return
new
cNumber
(
1
);
}
else
{
return
new
cNumber
(
wk
);
}
default
:
return
new
cNumber
(
wk
);
}
}
else
{
wk
=
parseInt
(((
dt
-
startOfYear
)
/
c_msPerDay
+
iso
[
startOfYear
.
getUTCDay
()]
+
7
)
/
7
);
return
new
cNumber
(
wk
);
}
}
cFormulaFunctionGroup
[
'
DateAndTime
'
]
=
cFormulaFunctionGroup
[
'
DateAndTime
'
]
||
[];
cFormulaFunctionGroup
[
'
DateAndTime
'
].
push
(
cDATE
,
cDATEDIF
,
cDATEVALUE
,
cDAY
,
cDAYS
,
cDAYS360
,
cEDATE
,
cEOMONTH
,
...
...
@@ -1043,39 +1071,10 @@
return
this
.
value
=
new
cError
(
cErrorType
.
not_numeric
);
}
function
WeekNumber
(
dt
,
iso
,
type
)
{
dt
.
setUTCHours
(
0
,
0
,
0
);
var
startOfYear
=
new
Date
(
Date
.
UTC
(
dt
.
getUTCFullYear
(),
0
,
1
));
var
endOfYear
=
new
Date
(
dt
);
endOfYear
.
setUTCMonth
(
11
);
endOfYear
.
setUTCDate
(
31
);
var
wk
=
parseInt
(((
dt
-
startOfYear
)
/
c_msPerDay
+
iso
[
startOfYear
.
getUTCDay
()])
/
7
);
if
(
type
)
{
switch
(
wk
)
{
case
0
:
// Возвращаем номер недели от 31 декабря предыдущего года
startOfYear
.
setUTCDate
(
0
);
return
WeekNumber
(
startOfYear
,
iso
,
type
);
case
53
:
// Если 31 декабря выпадает до четверга 1 недели следующего года
if
(
endOfYear
.
getUTCDay
()
<
4
)
{
return
new
cNumber
(
1
);
}
else
{
return
new
cNumber
(
wk
);
}
default
:
return
new
cNumber
(
wk
);
}
}
else
{
wk
=
parseInt
(((
dt
-
startOfYear
)
/
c_msPerDay
+
iso
[
startOfYear
.
getUTCDay
()]
+
7
)
/
7
);
return
new
cNumber
(
wk
);
}
}
var
weekdayStartDay
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
];
var
type
=
0
;
return
this
.
value
=
new
cNumber
(
W
eekNumber
(
Date
.
prototype
.
getDateFromExcel
(
arg0
.
getValue
()),
weekdayStartDay
,
type
));
new
cNumber
(
w
eekNumber
(
Date
.
prototype
.
getDateFromExcel
(
arg0
.
getValue
()),
weekdayStartDay
,
type
));
};
/**
...
...
@@ -1659,35 +1658,6 @@
cWEEKNUM
.
prototype
.
Calculate
=
function
(
arg
)
{
var
arg0
=
arg
[
0
],
arg1
=
arg
[
1
]
?
arg
[
1
]
:
new
cNumber
(
1
),
type
=
0
;
function
WeekNumber
(
dt
,
iso
,
type
)
{
dt
.
setUTCHours
(
0
,
0
,
0
);
var
startOfYear
=
new
Date
(
Date
.
UTC
(
dt
.
getUTCFullYear
(),
0
,
1
));
var
endOfYear
=
new
Date
(
dt
);
endOfYear
.
setUTCMonth
(
11
);
endOfYear
.
setUTCDate
(
31
);
var
wk
=
parseInt
(((
dt
-
startOfYear
)
/
c_msPerDay
+
iso
[
startOfYear
.
getUTCDay
()])
/
7
);
if
(
type
)
{
switch
(
wk
)
{
case
0
:
// Возвращаем номер недели от 31 декабря предыдущего года
startOfYear
.
setUTCDate
(
0
);
return
WeekNumber
(
startOfYear
,
iso
,
type
);
case
53
:
// Если 31 декабря выпадает до четверга 1 недели следующего года
if
(
endOfYear
.
getUTCDay
()
<
4
)
{
return
new
cNumber
(
1
);
}
else
{
return
new
cNumber
(
wk
);
}
default
:
return
new
cNumber
(
wk
);
}
}
else
{
wk
=
parseInt
(((
dt
-
startOfYear
)
/
c_msPerDay
+
iso
[
startOfYear
.
getUTCDay
()]
+
7
)
/
7
);
return
new
cNumber
(
wk
);
}
}
if
(
arg0
instanceof
cArea
||
arg0
instanceof
cArea3D
)
{
arg0
=
arg0
.
cross
(
arguments
[
1
]);
}
else
if
(
arg0
instanceof
cArray
)
{
...
...
@@ -1751,7 +1721,7 @@
}
return
this
.
value
=
new
cNumber
(
W
eekNumber
(
Date
.
prototype
.
getDateFromExcel
(
arg0
.
getValue
()),
weekdayStartDay
,
type
));
new
cNumber
(
w
eekNumber
(
Date
.
prototype
.
getDateFromExcel
(
arg0
.
getValue
()),
weekdayStartDay
,
type
));
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment