Krl 时间戳的相对格式
在过去的两天里,我编写了CS462办公时间应用程序。通知用户下一个办公时间段的时间。现在,它只是将格式设置为“周四(2月3日)下午3点”。不过,我希望它更智能一些,比如说“今天下午3点”或“明天上午10点” 这类似于推特在推特上的相对时间戳(上面写着“3分钟前”或“23小时前”;除此之外,还列出了日期)。然而,就我而言,情况恰恰相反,因为我们正在应对未来时代 基本上,它需要足够聪明,知道一个事件是今天还是明天。除此之外,我只想显示一周中的日期和日期Krl 时间戳的相对格式,krl,Krl,在过去的两天里,我编写了CS462办公时间应用程序。通知用户下一个办公时间段的时间。现在,它只是将格式设置为“周四(2月3日)下午3点”。不过,我希望它更智能一些,比如说“今天下午3点”或“明天上午10点” 这类似于推特在推特上的相对时间戳(上面写着“3分钟前”或“23小时前”;除此之外,还列出了日期)。然而,就我而言,情况恰恰相反,因为我们正在应对未来时代 基本上,它需要足够聪明,知道一个事件是今天还是明天。除此之外,我只想显示一周中的日期和日期 有没有办法用KRL做到这一点?我是否只需要使用
有没有办法用KRL做到这一点?我是否只需要使用逻辑并编写一个函数(或模块)?目前在KRL中没有内置的功能来实现这一点。您可能需要编写一个函数或模块来执行此操作,如果/当您这样做时,我希望看到它。这些是我拥有的函数:
// First define some constants to measuring relative time
now = time:now({"tz": "America/Denver"});
midnight = time:new("23:59:59.000-07:00");
tomorrow_midnight = time:add(midnight, {"days": 1});
yesterday_midnight = time:add(midnight, {"days": -1});
// Functions for calculating relative time
relativefuturedate = function(d){
ispast(d) => "today (past) at " + justtime(d)
| istoday(d) => "today at " + justtime(d)
| istomorrow(d) => "tomorrow at " + justtime(d)
| datetime(d);
};
istoday = function(d){
d > now && d <= midnight;
};
istomorrow = function(d){
not istoday(d) && d <= tomorrow_midnight;
};
ispast = function(d){
d < now;
};
isfuture = function(d){
d > now;
};
justtime = function(d){
time:strftime(d, "%l:%M %p");
};
datetime = function(d){
time:strftime(d, "%A (%B %e) at %l:%M %p");
};
//首先定义一些常数来测量相对时间
现在=时间:现在({“tz”:“美国/丹佛”});
午夜=时间:新(“23:59:59.000-07:00”);
明天午夜=时间:加上(午夜,{“天”:1});
昨天午夜=时间:加上(午夜,{“天”:-1});
//计算相对时间的函数
relativefuturedate=函数(d){
ispast(d)=>“今天(过去)”在“+justtime(d)
|istoday(d)=>“今天”+justtime(d)
|istomorrow(d)=>“明天”+justtime(d)
|日期时间(d);
};
istoday=功能(d){
现在&&d我一直在做一个,但还没有完成。我完成后会把它贴在这里。
rule first_rule {
select when pageview ".*"
pre {
today_9 = time:new("2011-02-09T09:00:00.000-07:00");
today_12 = time:new("2011-02-09T12:00:00.000-07:00");
today_4 = time:new("2011-02-09T16:00:00.000-07:00");
tomorrow_9 = time:new("2011-02-10T09:00:00.000-07:00");
tomorrow_4 = time:new("2011-02-10T16:00:00.000-07:00");
nextday_9 = time:new("2011-02-11T09:00:00.000-07:00");
relative_now = relativefuturedate(now);
relative_today_9 = relativefuturedate(today_9);
relative_today_12 = relativefuturedate(today_12);
relative_today_4 = relativefuturedate(today_4);
relative_tomorrow_9 = relativefuturedate(tomorrow_9);
relative_tomorrow_4 = relativefuturedate(tomorrow_4);
relative_nextday_9 = relativefuturedate(nextday_9);
message = <<
Now: #{relative_now}<br />
Today at 9: #{relative_today_9}<br />
Today at 12: #{relative_today_12}<br />
Today at 4: #{relative_today_4}<br />
Tomorrow at 9: #{relative_tomorrow_9}<br />
Tomorrow at 4: #{relative_tomorrow_4}<br />
Day after tomorrow at 9: #{relative_nextday_9}<br />
>>;
}
notify("Time calculations:", message) with sticky=true;
}