feat:增加DATETOWEEK表达式

This commit is contained in:
lvxiaojiao 2023-02-27 17:25:54 +08:00
parent be6f7ce1b8
commit 59ce750d6c
4 changed files with 49 additions and 51 deletions

View File

@ -265,9 +265,7 @@ test('formula:date', () => {
'DATERANGESPLIT("1676563200,1676735999", "end" , "YYYY.MM.DD hh:mm:ss")'
)
).toBe('2023.02.18 11:59:59');
expect(evalFormual('DATETOWEEK("2023-02-27")')).toBe(
moment('2023-02-27').day()
);
expect(evalFormual('WEEKDAY("2023-02-27")')).toBe(moment('2023-02-27').day());
});
test('formula:last', () => {

View File

@ -612,6 +612,20 @@
返回现在的日期
### WEEKDAY
用法:`WEEKDAY(date)`
* `date:any` 日期
返回:`number` 星期几的数字标识
获取日期的星期几从0到6分别表示星期日、一、二...六
示例:
WEEKDAY('2023-02-27') 得到 1
### DATETOSTR
用法:`DATETOSTR(date, 'YYYY-MM-DD')`
@ -652,20 +666,6 @@ DATERANGESPLIT('1676563200, 1676735999', 'start' , 'YYYY.MM.DD hh:mm:ss') 得到
DATERANGESPLIT('1676563200, 1676735999', 1 , 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.18 11:59:59'
DATERANGESPLIT('1676563200, 1676735999', 'end' , 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.18 11:59:59'
### DATETOWEEK
用法:`DATETOWEEK(date)`
* `date:any` 日期
返回:`number` 星期几的数字标识
获取日期的星期几从0到6分别表示星期日、一、二...六
示例:
DATETOWEEK('2023-02-27') 得到 1
### STARTOF
用法:`STARTOF(date[unit = "day"])`

View File

@ -1029,6 +1029,23 @@ export const doc: {
},
namespace: "日期函数"
},
{
name: "WEEKDAY",
description: "获取日期的星期几从0到6分别表示星期日、一、二...六\n\n示例\n\nWEEKDAY('2023-02-27') 得到 1",
example: "WEEKDAY(date)",
params: [
{
type: "any",
name: "date",
description: "日期"
}
],
returns: {
type: "number",
description: "星期几的数字标识"
},
namespace: "日期函数"
},
{
name: "DATETOSTR",
description: "对日期、日期字符串、时间戳进行格式化\n\n示例\n\nDATETOSTR('12/25/2022', 'YYYY-MM-DD') 得到 '2022.12.25'\nDATETOSTR(1676563200, 'YYYY.MM.DD') 得到 '2023.02.17'\nDATETOSTR(1676563200000, 'YYYY.MM.DD hh:mm:ss') 得到 '2023.02.17 12:00:00'\nDATETOSTR(DATE('2021-12-21'), 'YYYY.MM.DD hh:mm:ss') 得到 '2021.12.21 08:00:00'",
@ -1083,23 +1100,6 @@ export const doc: {
},
namespace: "日期函数"
},
{
name: "DATETOWEEK",
description: "获取日期的星期几从0到6分别表示星期日、一、二...六\n\n示例\n\nDATETOWEEK('2023-02-27') 得到 1",
example: "DATETOWEEK(date)",
params: [
{
type: "any",
name: "date",
description: "日期"
}
],
returns: {
type: "number",
description: "星期几的数字标识"
},
namespace: "日期函数"
},
{
name: "STARTOF",
description: "返回日期的指定范围的开端",

View File

@ -1500,6 +1500,23 @@ export class Evaluator {
return new Date();
}
/**
* 06...
*
*
*
* WEEKDAY('2023-02-27') 1
*
* @example WEEKDAY(date)
* @namespace
* @param {any} date
*
* @returns {number}
*/
fnWEEKDAY(date: Date | string | number) {
return moment(this.normalizeDate(date)).day();
}
/**
*
*
@ -1575,23 +1592,6 @@ export class Evaluator {
return dateArr;
}
/**
* 06...
*
*
*
* DATETOWEEK('2023-02-27') 1
*
* @example DATETOWEEK(date)
* @namespace
* @param {any} date
*
* @returns {number}
*/
fnDATETOWEEK(date: Date | string | number) {
return moment(this.normalizeDate(date)).day();
}
/**
*
*