2015-10-01 92 views
0

與時間計算我會讓帖子的時間戳在傑基爾基於這樣的網站:在傑基爾

{{ post.date | date: "%Y%m%dT%H%M" }}00Z 

我現在儘量使post.date + 3hours這樣

{{ post.date + 3/24 | date: "%Y%m%dT%H%M" }}00Z 

雖然傑基爾似乎解析這只是罰款,結果是根本沒有改變(仍然顯示post.date而不是post.date + 3hours

那麼如何添加3小時的post.date

注意:這是爲事件創建ics文件,所以post.date是開始日期和時間,結束日期和時間是3小時後。

回答

0

這個想法是添加秒日期時間戳(page.date | date: '%s')。

_includes/schedule.html是自我說明:

{% comment %}+++++++++++++++++++++++++++++++++++++++ 
this include can be called with or without vars 

hoursToAdd : int number of hours to add 
minutesToAdd : int number of minutes to add 

// include with no vars - default duration is applied 
{% include schedule.html %} 

// include with vars 
{% include schedule.html hoursToAdd=1 minutesToAdd=30 %} 
or 
{% include schedule.html minutesToAdd=35 %} 
+++++++++++++++++++++++++++++++++++++{% endcomment %} 

{% assign defaultDuration = 3 %} 

{% if include.hoursToAdd %} 
    {% assign hoursToSec = include.hoursToAdd | times: 3600 %} 
{% else %} 
    {% assign hoursToSec = defaultDuration | times: 3600 %} 
{% endif %} 

{% if include.minutesToAdd %} 
    {% assign minutesToSec = include.minutesToAdd | times: 60 %} 
{% else %} 
    {% assign aminutesToSec = 0 %} 
{% endif %} 

{% comment %} ++ Compute endTime : translate to timestamp and add second ++{% endcomment %} 
{% assign endTime = page.date | date: '%s' | plus: hoursToSec | plus: minutesToSec %} 

{% comment %} ++ Output ++{% endcomment %} 
<p> 
    from {{ page.date | date: "%Y%m%dT%H%M" }}00Z 
    to {{ endTime | date: "%Y%m%dT%H%M" }}00Z 
</p>