我正在尝试设置电报即时视图。我面临着函数datetime @datetime
的问题,我看了official documentation。
我有以下日期Jul 19, 2018 at 2:25pm
。如果我们在该日期的同一年,该字符串将不包含年份:Jul 19 at 2:25pm
表示今年7月19日。我怎样才能处理缺失的一年?
到目前为止这是我的代码。
@datetime(-2, "en-US", "LLL d 'at' k:mm"): "Jan 25 at 2:44pm"
published_date: $@
#manage the current year case
@datetime(0, "en-US", "LLL d, YYYY 'at' k:mma"): "Jan 25, 2018 at 2:44pm"
published_date: $@
截至目前,缺失的一年没有得到妥善管理。通过这种方式,这一年总是1970年。
该算法如下:
YYYY
解析日期$pubslished_date
将包含0或一些垃圾(尝试@debug
它)。所以你可以使用像@if_not( $published_date ) { ... }
这样的东西,在那里你可以尝试解析没有YYYY
的日期。不要忘记用published_date!: …
强制重新定义变量。如果这不起作用,请尝试使用条件绑定:pubslihed_date?: …
。它有相同的逻辑。 (只是在当前代码的第二个绑定中加上?
问号)。