question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] support dates

See original GitHub issue

The general idea is to support the usage of date variables passed in as strings with some form of operator/type specifier to identify them as dates. The primary goal is to support comparison operators.

Example: {“<”:[{“date”: “2016-10-01T03:24:00.000Z”}, {“date”: “2016-10-15T03:24:00.000Z”}]}

Prototype:

"date" : function(a) {
        return(new Date(a));
    }

Example with var - works with date function in place: rule: {“<”:[{“date”:{“var”:“submitDate”}}, {“date”:{“var”: “dueDate”}}]} data: {“submitDate”:“2016-10-01T03:24:00.000Z”,“dueDate”:“2016-10-15T03:24:00.000Z”}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
jwadhamscommented, Oct 28, 2016

I still need to write some documentation, but I added the method jsonLogic.add_operation yesterday and I think it can solve this case. Here’s an example where string comparison does the wrong thing for two ISO 8601 dates (one Zulu time, the other Pacific time) and then using Date.parse to compare them correctly.

jsonLogic.add_operation('Date', Date);

jsonLogic.apply(
  {"<":[
    "2016-10-01T03:24:00.000Z",
    "2016-10-01T03:24:00.000-0800"
  ]}
); //false

jsonLogic.apply(
  {"<":[
    {"Date.parse" : "2016-10-01T03:24:00.000Z"},
    {"Date.parse" : "2016-10-01T03:24:00.000-0800"}
  ]}
); //true

And of course it works with vars too:

jsonLogic.add_operation('Date', Date);

var data = {
  gmt : "2016-10-01T03:24:00.000Z",
  pst : "2016-10-01T03:24:00.000-0800"
};

jsonLogic.apply(
  {"<":[
    {"var":"gmt"},
    {"var":"pst"}
  ]},
  data
);//false

jsonLogic.apply(
  {"<":[
    {"Date.parse" : {"var":"gmt"} },
    {"Date.parse" : {"var":"pst"} }
  ]},
  data
); //true

And it’s user’s choice whether they want to use the built-in Date or they need something heavier duty like moment.js.

Does this do what you need it to?

0reactions
robmurthacommented, Oct 28, 2016

That should work thanks!

On 28 October 2016 at 12:17, Jeremy Wadhams notifications@github.com wrote:

BTW, by “yesterday” I mean “v1.0.9” which was on Bower yesterday but didn’t go up on NPM until this morning.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jwadhams/json-logic-js/issues/6#issuecomment-256963561, or mute the thread https://github.com/notifications/unsubscribe-auth/ABgg8qoZ2jZwDFxAMrfUXfqN4POd1evhks5q4iA0gaJpZM4KU7ev .

Rob Murtha 302-359-5943

http://www.linkedin.com/in/robmurtha http://www.twitter.com/robmurtha

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10 Enterprise and Education - Microsoft Lifecycle
Microsoft will continue to support at least one Windows 10 release until October 14, 2025. Support dates are shown in the Pacific Time...
Read more >
Microsoft Windows - endoflife.date
Windows 11, version 22H2 (W), 3 months and 1 week ago. (20 Sep 2022). Ends in 1 year and 9 months. (14 Oct...
Read more >
Windows 10 lifecycle details - Pureinfotech
On Windows 10, feature updates are released twice a year through the Semi-Annual Channel (SAC), governed by the new Modern Lifecycle Policy.
Read more >
Reference Point: All Windows 10 Versions Release & EOL ...
What we do know is that Microsoft will be supporting Windows 10 until 14 October 2025, as per their lifecycle fact sheet, so...
Read more >
IBM Software End of Support - Overview
End of support dates are generally effective on 30 April and 30 September. There are exceptions. Once a specific version or release reaches...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found