gjtorikian / jekyll-last-modified-at

A Jekyll plugin to show the last_modified_at time of a post.
MIT License
242 stars 38 forks source link

{{ page.last_modified_at | date }} #25

Closed tjkohli closed 10 years ago

tjkohli commented 10 years ago

Hi! First of all, this is the best Gem ever. Secondly, I found a bug/issue? I usually solve things on my own, but I cannot figure this out.

If I use this:

{{ page.last_modified_at | date: '%-m/%-d/%y at %-I:%M:%S %p' }}

... I expect this out of it: 8/20/14 at 6:00:34 PM

But instead, I get this: 8/20/14 at 12:00:00 AM

No matter what, the time is always 12:00AM. Why?


{% last_modified_at %-m/%-d/%y at %-I:%M:%S %p %}

This^ seems to output just fine in any given page, but I need to get last modified dates in a for loop.

gjtorikian commented 10 years ago

Can you try setting the timezone in your Jekyll site: http://jekyllrb.com/docs/configuration/

I have seen many time related problems as a result of this.

parkr commented 10 years ago

If you're using GitHub Pages, it's being run in the Pacific timezone (UTC-8 or -7 or something). Additionally, it's possible that the Time objects are being created in UTC, so when you ask for them in your time zone, Ruby spits out the difference, not the inputted time.

TIME TRAVEL

tjkohli commented 10 years ago

Thanks for your quick reply guys. @gjtorikian I set the timezone: America/New_York and no luck. The list still says 12:00AM for every page. If I write the last_modified_at date to any given page, however, it writes perfectly. But as I said, in a for loop, time seems to default to 12:00AM (but date works as expected in any situation).

@parkr I am not using Github pages, but thanks for the information. I plan to use Github pages in the future, but not for this project. Even if it spat out the time difference, though, why would it always be 12:00AM regardless of modified time?

I am willing to cooperate with any testing or code sharing. Being a Node/JavaScript/HTML/CSS developer, I am new to Ruby, but I know my way around Jekyll, and I'm working on a pretty robust client project which requires a page containing a list of all site pages with their last_modified_at in a table.

parkr commented 10 years ago

It'd only ever be consistently 12 AM if it couldn't find any time information.

tjkohli commented 10 years ago

@parkr Right, which is why it leads me to believe that last_modified_at fails to find time information when used in a loop. It only gets the date.

Yet, it finds the time information perfectly when it's not used in a loop (if it's used directly on a page, for example).

parkr commented 10 years ago

On the exact same post/page?

tjkohli commented 10 years ago

Yes, for all pages, and within each page. Here is a reduction of my code, from one page, and each tag's respective output:

{{ site.time }}2014-08-23 18:28:59 -0400

{{ site.time | date: '%-m/%-d/%y at %-I:%M:%S %p' }}8/23/14 at 6:28:59 PM


{% last_modified_at %}23-Aug-14

{% last_modified_at %-m/%-d/%y at %-I:%M:%S %p %}8/23/14 at 6:28:58 PM


{{ page.last_modified_at }}23-Aug-14

{{ page.last_modified_at | date: '%-m/%-d/%y at %-I:%M:%S %p' }}8/23/14 at 12:00:00 AM

gjtorikian commented 10 years ago

It may just be me, but I can't get the {{ page.last_modified_at }} notation to work out at all locally. It just prints out an empty string--so it's very hard to test where the problem is. I'm on Jekyll 2.3 if it matters.

tjkohli commented 10 years ago

I'm also on 2.3. I can get you a sample project later if you'd like.

gjtorikian commented 10 years ago

@SpectrumPixel That would be fantastic. Sorry for the trouble, this is really perplexing.

tjkohli commented 10 years ago

No problem. It's not trouble at all. It's all in the name of bettering our software together!

Here is a live demo, and a link to download the src files: [[ removed ]]

parkr commented 10 years ago

@SpectrumPixel can you try applying the fix in #26 and letting me know if it works?

gjtorikian commented 10 years ago

Here is a live demo

Super wild. I see the time on your live demo, clearly, but here's what I get locally:

screen shot 2014-08-25 at 4 18 21 pm

parkr commented 10 years ago

@gjtorikian did you forget part of the img?

gjtorikian commented 10 years ago

Well, the upper part I excluded. What the image shows is that locally, page.last_modified_at doesn't render.

gjtorikian commented 10 years ago

Okay, nevermind. Got it to work locally.

gjtorikian commented 10 years ago

Aaaaaand @parkr your fix didn't change anything. :cry:

gjtorikian commented 10 years ago

I'm beginning to think that this has to do with Jekyll's date filter. I can't conceive of why this isn't working at the moment.

parkr commented 10 years ago

Liquid makes the date filter. Does it work with any of Jekyll's date-related filters? https://github.com/jekyll/jekyll/blob/master/lib/jekyll/filters.rb#L50-L94

gjtorikian commented 10 years ago

Ayup. But then you can't pass in your own format.

The thing that really bothers me is that even with timezone in the config, it still shows up as midnight.

parkr commented 10 years ago

Ayup. But then you can't pass in your own format.

If it works with those then we know it's in Liquid, not in Jekyll.

it still shows up as midnight.

That means the time information is lost.

gjtorikian commented 10 years ago

I might've just figured something out. I attached %Z to the string to get the time zone, and it spat out PDT (with the same 12:00 AM time). So it's not falling back to UTC or whatever. That might mean that the time object from Git is not providing the right time zone?

parkr commented 10 years ago

I FIGURED IT OUT

Determinator#to_liquid returns a String. Given the base format, this is then passed to the date filter which parses it as a date (no time info) and spits out the format you want above but has no time info to print so defaults to midnight in the system's timezone.

We should return a Time object there and format in the tag.

parkr commented 10 years ago

27 should take care of it, methinks!!!!!!

tjkohli commented 10 years ago

27 Fixed it for me! I think.

EDIT: Yup. I can confirm. The time now shows, is properly formatted, and is indeed the real modification time.

Thanks guys!!!

gjtorikian commented 10 years ago

@SpectrumPixel Thanks for the awesome reproduction case!

tjkohli commented 10 years ago

@gjtorikian @parkr No problem! It's the least I could do to help you two cool guys out.

Doesn't it look great? :) screen shot 2014-08-26 at 8 38 04 am

parkr commented 10 years ago

Looks awesome! :+1: