Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "today" when using date filter #193

Closed
pdehaan opened this issue Feb 18, 2020 · 1 comment
Closed

Add support for "today" when using date filter #193

pdehaan opened this issue Feb 18, 2020 · 1 comment

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Feb 18, 2020

liquidjs @ v9.7.0

Per https://shopify.github.io/liquid/filters/date/

To get the current time, pass the special word "now" (or "today") to date:

Looks like the "now" case works w/ liquidjs, but not the "today" keyword.

it('should create a new Date when given "now"', function () {
return test('{{ "now" | date: "%Y"}}', (new Date()).getFullYear().toString())
})

const assert = require("assert");

const pkg = require("liquidjs/package.json");
const { Liquid } = require('liquidjs');
const engine = new Liquid({
  strictFilters: true
});

main()
  .catch(err => {
    console.error(err.message);
    process.exit(2);
  });

async function main() {
  console.log(`${pkg.name} @ v${pkg.version}`); // liquidjs @ v9.7.0

  const article = {article:{published_at: new Date(2015, 6, 17)}};

  const ex1 = await engine.parseAndRender(`{{ article.published_at | date: "%a, %b %d, %y" }}`, article);
  assert.strictEqual(ex1, "Fri, Jul 17, 15");

  const ex2 = await engine.parseAndRender(`{{ article.published_at | date: "%Y" }}`, article);
  assert.strictEqual(ex2, "2015");

  const ex3 = await engine.parseAndRender(`{{ "March 14, 2016" | date: "%b %d, %y" }}`);
  assert.strictEqual(ex3, "Mar 14, 16");

  const ex4 = await engine.parseAndRender(`{{ "now" | date: "%Y-%m-%d %H:%M" }}`);
  assert.notStrictEqual(ex4, "now");

  const ex5 = await engine.parseAndRender(`{{ "today" | date: "%Y-%m-%d %H:%M" }}`);
  assert.strictEqual(ex4, ex5);
  assert.notStrictEqual(ex5, "today");

  console.log("SUCCESS!");
}

OUTPUT

Expected values to be strictly equal:
+ actual
- expected

+ '2020-02-18 14:51'
- 'today'
harttle pushed a commit that referenced this issue Feb 20, 2020
# [9.8.0](v9.7.2...v9.8.0) (2020-02-20)

### Features

* "today" when using date filter, fixes [#193](#193) ([185312d](185312d))
@harttle
Copy link
Owner

harttle commented Feb 20, 2020

🎉 This issue has been resolved in version 9.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants