【发布时间】:2019-07-22 05:11:58
【问题描述】:
我有一个函数,我想用它来返回电子签名的状态。每当用户对表单进行电子签名时,都会发生这种情况。
所以我写了以下函数:
setTimeDiffStatement(time: number): string {
const timeMsgArray = new Array(4);
// Within the hour, return
timeMsgArray[0] = ' 15 minutes ago';
// Within the date, return
timeMsgArray[1] = ' at 2:35 pm';
// Within the week return
timeMsgArray[2] = ' on Monday';
// Outside the week return
timeMsgArray[3] = ' on ' + this.theDate.getMonth() + this.theDate.getDay() + this.getOrdinalNum(this.theDate.getDay()) + ' ' + this.theDate.getFullYear();
const timeMsg = '';
return '';
}
这是 getOrdinalNum 的代码
getOrdinalNum(n: number): string {
return n + (n > 0 ? ['th', 'st', 'nd', 'rd'][(n > 3 && n < 21) || n % 10 > 3 ? 0 : n % 10] : '');
}
当我调用第一个函数时,我需要根据我们使用 Moment.js 的时间返回一个 timeArrayMessages
所以,使用这个函数,我得到了日期名称,我想将时间传递给上面的第一个函数,然后像下面这个函数一样构建它:
getDayName(daynbr: number): string {
const weekday = new Array(7);
weekday[0] = 'Sunday';
weekday[1] = 'Monday';
weekday[2] = 'Tuesday';
weekday[3] = 'Wednesday';
weekday[4] = 'Thursday';
weekday[5] = 'Friday';
weekday[6] = 'Saturday';
const n = weekday[daynbr];
return n;
}
请告诉我实现这些业务规则的简单方法:
当表单被电子签名时,然后在伪代码中
Within the hour, return "15 minutes ago"
Within the date, return "at 2:35 pm"
Within the week return "on Monday"
Outside the week return "on July 10th"
【问题讨论】:
标签: typescript angular6 momentjs