gjtorikian / jekyll-last-modified-at

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

Formatted date tests fail depending on timezone #56

Closed jayvdb closed 4 years ago

jayvdb commented 6 years ago

On my local machine, in TZ Asia/Jakarta, I see four test failures. I am fairly confident that is because Time.strftime emits local time, and I am thus seeing off-by-one days because of my timezone.

These errors can be reproduced by adding timezone: Asia/Jakarta to ./spec/fixtures/_config.yml, and fixed by setting it to timezone: UTC.

$ bundle exec rspec ./spec/jekyll-last-modified-at/determinator_spec.rb
F....F....

Failures:

  1) Jekyll::LastModifiedAt::Determinator knows the last modified date of the file in question
     Failure/Error: expect(subject.formatted_last_modified_date).to eql("15-Jan-14")

       expected: "15-Jan-14"
            got: "16-Jan-14"

       (compared using eql?)
     # ./spec/jekyll-last-modified-at/determinator_spec.rb:10:in `block (2 levels) in <top (required)>'

  2) Jekyll::LastModifiedAt::Determinator#to_s returns the formatted date
     Failure/Error: expect(subject.to_s).to eql("15-Jan-14")

       expected: "15-Jan-14"
            got: "16-Jan-14"

       (compared using eql?)
     # ./spec/jekyll-last-modified-at/determinator_spec.rb:41:in `block (3 levels) in <top (required)>'

$ bundle exec rspec ./spec/plugins/last_modified_at_spec.rb
FF...

Failures:

  1) Last Modified At Tag A committed post file has last revised date
     Failure/Error: expect(@post.output).to match /Article last updated on 03-Jan-14/

       expected "<html>\n  <head>\n    <title>last-modified-at</title>\n  </head>\n  <body>\n    <span class=\"last-modified-at\">Article last updated on 04-Jan-14</span>\n\n    <p>Yay.</p>\n\n  </body>\n</html>\n" to match /Article last updated on 03-Jan-14/
       Diff:
       @@ -1,2 +1,12 @@
       -/Article last updated on 03-Jan-14/
       +<html>
       +  <head>
       +    <title>last-modified-at</title>
       +  </head>
       +  <body>
       +    <span class="last-modified-at">Article last updated on 04-Jan-14</span>
       +
       +    <p>Yay.</p>
       +
       +  </body>
       +</html>

     # ./spec/plugins/last_modified_at_spec.rb:12:in `block (3 levels) in <top (required)>'

  2) Last Modified At Tag A committed post file passes along last revised date format
     Failure/Error: expect(@post.output).to match /Article last updated on 2014:January:Saturday:04/

       expected "<html>\n  <head>\n    <title>last-modified-at-with-format</title>\n  </head>\n  <body>\n    <span cl...\">Article last updated on 2014:January:Sunday:05</span>\n\n    <p>Yay.</p>\n\n  </body>\n</html>\n" to match /Article last updated on 2014:January:Saturday:04/
       Diff:
       @@ -1,2 +1,12 @@
       -/Article last updated on 2014:January:Saturday:04/
       +<html>
       +  <head>
       +    <title>last-modified-at-with-format</title>
       +  </head>
       +  <body>
       +    <span class="last-modified-at">Article last updated on 2014:January:Sunday:05</span>
       +
       +    <p>Yay.</p>
       +
       +  </body>
       +</html>

     # ./spec/plugins/last_modified_at_spec.rb:17:in `block (3 levels) in <top (required)>'