mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
feat:增加DATETOWEEK表达式
This commit is contained in:
parent
c5a1b4bd76
commit
be6f7ce1b8
@ -265,6 +265,9 @@ 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()
|
||||
);
|
||||
});
|
||||
|
||||
test('formula:last', () => {
|
||||
|
@ -652,6 +652,20 @@ 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"])`
|
||||
|
@ -1083,6 +1083,23 @@ 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: "返回日期的指定范围的开端",
|
||||
|
@ -1470,7 +1470,10 @@ export class Evaluator {
|
||||
* @returns {number} 时间戳
|
||||
*/
|
||||
fnTIMESTAMP(date: Date, format?: 'x' | 'X') {
|
||||
return parseInt(moment(date).format(format === 'x' ? 'x' : 'X'), 10);
|
||||
return parseInt(
|
||||
moment(this.normalizeDate(date)).format(format === 'x' ? 'x' : 'X'),
|
||||
10
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1572,6 +1575,23 @@ export class Evaluator {
|
||||
return dateArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日期的星期几,从0到6分别表示星期日、一、二...六
|
||||
*
|
||||
* 示例:
|
||||
*
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回日期的指定范围的开端
|
||||
*
|
||||
@ -1582,7 +1602,7 @@ export class Evaluator {
|
||||
* @returns {date} 新的日期对象
|
||||
*/
|
||||
fnSTARTOF(date: Date, unit?: any) {
|
||||
return moment(date)
|
||||
return moment(this.normalizeDate(date))
|
||||
.startOf(unit || 'day')
|
||||
.toDate();
|
||||
}
|
||||
@ -1596,7 +1616,7 @@ export class Evaluator {
|
||||
* @returns {date} 新的日期对象
|
||||
*/
|
||||
fnENDOF(date: Date, unit?: any) {
|
||||
return moment(date)
|
||||
return moment(this.normalizeDate(date))
|
||||
.endOf(unit || 'day')
|
||||
.toDate();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user