angular - 按天数计算的角管返回等级
问题描述
我创建了一个管道来根据过去和当前值之间的天数差异返回类,但它总是返回类,就好像日期总是迟到一样。
我想根据条件关闭的日子返回。
transform(value: any, ...args: any[]): any {
this.now = Date.now();
this.now = new Date(this.now).toISOString();
this.now = Date.parse(this.now);
this.forecast = new Date(value).toISOString();
this.forecast = Date.parse(this.forecast);
this.diff = this.now - this.forecast;
if(this.forecast < this.now){
return 'is__border-left-danger';
}
else if (this.diff < 172800) /** less than 2 days */
{
return 'is__border-left-danger';
}
else if (this.diff > 172800 || this.diff < 345600) /** between 2 days and 4 days */
{
return 'is__border-left-warning';
}
else /** otherwise */
{
return 'is__border-left-success';
}
}
解决方案
转换(值:任何,...args:任何 []):任何 { this.now = Date.now();
// Make sure before subtracting dates both should be in milliseconds. If it's not in milliseconds then multiply it by 1000
this.forecast = new Date(value).toISOString(); // I didn't find it usefull
this.forecast = Date.parse(this.forecast);
this.diff = Math.abs(this.now - this.forecast); // Your comparison below need only diff so use Math.abs() function
if(this.forecast < this.now){
return 'is__border-left-danger';
}
else if (this.diff < 172800) /** less than 2 days */
{
return 'is__border-left-danger';
}
else if (this.diff > 172800 || this.diff < 345600) /** between 2 days and 4 days */
{
return 'is__border-left-warning';
}
else /** otherwise */
{
return 'is__border-left-success';
}
}
检查这个可能有用=> https://www.epochconverter.com/
推荐阅读
- excel - 我想使用 vba 编辑现有 power point 幻灯片中的文本
- python - 不是在 __init__ 中定义的所有属性?
- python - 使用 python 3 进行多处理:当我的子进程完成时,它会杀死另一个进程
- python - 抓取 Youtube 频道最后一天的视频 - bs4
- html - CSS 类似乎不存在
- javascript - 为 useState() 钩子字符串化对象以避免重新渲染是一种好习惯吗
- jpa - Crieria API 查询使用具有不存在关系的条件生成器.construct
- .net-core - 全局查询过滤器 - 这是如何工作的?
- android - 通过 Android Media Store 将图像存储在新文件夹中
- python - 形状不匹配、2D 输入和 2D 标签