这些是我拥有的功能:
// 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");
};
这应该可以解决问题。现在我正在用这个规则测试它:
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;
}
但是,这似乎还没有奏效。我得到这个输出:
任何人都可以看到有什么问题吗?