loopback4正则表达式-匹配任何东西

时间:2019-12-20 13:47:18

标签: regex pattern-matching loopbackjs loopback4

我使用loopback4。我该如何使日期时间与时区匹配。我只对hour参数感​​兴趣:“ finalhour” 示例:2019-12-20T10:22:50.143Z ==> 2019-12-20Tfinalhour:22:50.143Z

我尝试过这样的操作:const pattern=await '^'+"T"+finalhour+'^' ,但是环回通常将其读取为^ T10 ^

在论坛上经过长时间的搜索后,我求助于您。如果您能帮助我,我将很感激

2 个答案:

答案 0 :(得分:0)

据我了解,您想构建一个与freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134) at freemarker.core.UnexpectedTypeException.newDescriptionBuilder(UnexpectedTypeException.java:85) 相匹配的正则表达式。

您可以使用此默认的ISO日期时间正则表达式

2019-12-20TsomeNumber:22:50.143Z

并对其进行修改,以将您的(\d{4})-(\d{2})-(\d{2})T(\d{2})\:(\d{2})\:(\d{2})\.\d{3,4}Z 变量放入其中。

finalhour

此外,您这里不需要let finalHour = 10; // when building regex from constructor, we need to espace the backslash ( \ ) // i did not know that. let regex = new RegExp('(\\d{4})-(\\d{2})-(\\d{2})T' + finalHour + '\\:(\\d{2})\\:(\\d{2})\\.\\d{3,4}\\Z'); let test = '2019-12-20T10:22:50.143Z'; console.log(regex.test(test));关键字,因为您正在构建一个字符串,而不是在等待诺言。

答案 1 :(得分:0)

我需要返回每小时的订单数量。所以我尝试这种解决方案,但返回错误比较,例如,如果我在小时:10有一个订单,则返回6

 @get('/orders/count-perHour/{date}', {
    responses: {
      '200': {
        description: 'Order model count',
        content: { 'application/json': { schema: CountSchema } },
      },
    },
  })
  async countPerHour(
    @param.path.string('date') date: string): Promise<any> {
    let dateStart = new Date(date);
    dateStart.setSeconds(0);
    dateStart.setMinutes(0);

    let dateEnd = new Date(date);
    dateEnd.setSeconds(59);
    dateEnd.setMinutes(59);

    return await this.orderRepository.count(
      {
        createdAt: {
          lte: dateEnd
          ,
          gte: dateStart
        }
      }
    );
  }

相关问题