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.

Support for semantic date queries

See original GitHub issue

The idea is that we add support for queries that look like this:

where: {
  myDateTime: {
    _semantic: {
      value: "TODAY",
      timezone: "+6:00"
    }
  }
}

Timezone could default to server time.

{
  myDateTime: {
    _semantic: {
      value: "NEXT_N_DAYS",
      n: 22
    }
  }
}
{
  myDateTime: {
    _semantic: {
      value: "PAST_N_WEEKS",
      timezone: "+6:00",
      n: 3
    }
  }
}
{
  myDateTime: {
    _semantic: {
      value: "LAST_MONTH",
      timezone: "+6:00"
    }
  }
}
{
  myDateTime: {
    _semantic: {
      value: "NEXT_N_HOURS",
      timezone: "+6:00",
      n: 3
    }
  }
}

These are inspired by the Salesforce API which calls them literals. See: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

The SQL can be implemented something like this:

Yesterday for example:

(
    "myDateTimeField" >= (date_trunc('DAY', now() AT TIME ZONE '+6:00') - '1 DAY'::INTERVAL) AT TIME ZONE '+6:00' AND "myDateTimeField" < (date_trunc('DAY', now() AT TIME ZONE '+6:00')) AT TIME ZONE '+6:00'
    )

Or parameterized:

pg.query(
  "?? >= (date_trunc('DAY', now() AT TIME ZONE ?) - '1 DAY'::INTERVAL) AT TIME ZONE ? AND ?? < (date_trunc('DAY', now() AT TIME ZONE ?)) AT TIME ZONE ?", 
 [field, zone, zone, field, zone, zone]
)

I can collaborate to produce the SQL required for the other semantic dates that we want to support if this feature request has merit.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:40
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
treyhuffinecommented, Dec 24, 2020

Is there any movement on this? This would be an awesome addition!

5reactions
cthurstoncommented, Aug 12, 2019

Salesforce does it this way: “PAST_N_WEEKS:3” Which I didn’t like as much as having n outside the string because the client would have to build the string rather than just pass n as a variable.

I suppose you could put the timezone in as well: “PAST_N_WEEKS:3:+6:00” But now the timezone has a colon so you may want a different delimiter. “PAST_N_WEEKS,3,+6:00”

Looks impossible to validate.

_semantic: "PAST_N_WEEKS,3,+6:00"

OR

We could make them all keys:

_semantic: {
   _yesterday: true
}
_semantic: {
   _yesterday: 1
}
_semantic: {
   _past_n_weeks: 3
   _timezone: "+6:00"
}

or some combination with some string parsing

_semantic: {
   _yesterday: "+6:00"
}
_semantic: {
   _past_n_weeks: "3,+6:00"
}

OR

Nesting with a required interval-type object

_semantic: {
   _yesterday: {
    _timezone: "+6:00"
    _value: 1
  }
}

defaults to server timezone and _value of 1 maybe

_semantic: {
   _yesterday: {}
}
_semantic: {
   _past_n_weeks: {
     _timezone: "+6:00"
     _value: 3
  }
}

The nested syntax would look great in graphiQL.

With the keys they could even be taken out of the _semantic namespace and be top level, but maybe too messy to have _gte and _yesterday on the same tier.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Help:Date parsing - semantic-mediawiki.org
Description: In order to select by date in inline queries it is necessary to specify dates with 2022, 12 etc separated by '-'...
Read more >
Querying for date range in SPARQL - Stack Overflow
I'm trying to filter this list of objects down to one item by date; my query input is unfortunately only precise to the...
Read more >
Semantic Graph Developer's Guide — Chapter 6
where hostname is the name of your MarkLogic Server host. From the Query Type drop-down list, select SPARQL Query. The Query Console supports...
Read more >
Semantic date picker - CodePen
<link href="https://cdn.rawgit.com/mdehoog/Semantic-UI/6e6d051d47b598ebab05857545f242caf2b4b48c/dist/semantic.min.css" rel="stylesheet" type="text/css" />.
Read more >
date_input: Define simple date input with Semantic UI styling
date_input( input_id, label = NULL, value = NULL, min = NULL, max = NULL, style = NULL, icon_name = "calendar" ) dateInput( inputId,...
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