Last active
December 2, 2017 19:41
-
-
Save 13protons/72c6d22d95f3ed80a511 to your computer and use it in GitHub Desktop.
Localize dates in Jekyll template without specifying timezone offset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A tiny Jekyll filter for giving custom dates a proper timezone offset | |
# example usage `{{ post.startDate | tz_local | date: '%l:%M %P'}}` | |
# Why? If you omit a timezone offset, Jekyll automatically adds +0000...which is probably not what you want. | |
# This let's dates like `startDate: 2015-1-14 18:00:00` render correcty in local time. DST is calculated correctly | |
# NOTE: This will still inherit Jekyll's timezone property as set in _config.yml | |
module TZLocal | |
def tz_local(input) | |
input = input + (Time.parse(input.to_s).gmt_offset) * -1 | |
end | |
end | |
Liquid::Template.register_filter(TZLocal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this snippet. Should really be part of Jekyll in my opinion.