Skip to content

Relative Time Queries #360

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

Merged
merged 8 commits into from
Oct 31, 2017

Conversation

montymxb
Copy link
Contributor

Following #4289 in parse-server, this brings in relative time queries as an additional sorting mechanism. Queries can now be modified to sort via relative time as follows.

// relative queries either start with 'in' or end in 'ago'
// but not both!

...
// less than 1 day ago
$query->lessThanRelativeTime('createdAt', '1 day ago');

...
// greater than 7 days and 30 minutes ago
$query->greaterThanRelativeTime('updatedAt', '7 days 30 minutes ago');

...
// less than or equal to 14 days in the future
$query->lessThanOrEqualToRelativeTime('date', 'in 14 days');

...
// greater than or equal to 5 days, 6 hrs, 14 mins & 30 seconds in the future
$query->greaterThanOrEqualToRelativeTime(
    'purchase_date', 
    'in 5 days 6 hrs 14 mins 30 secs'
);

...
// get stuff from the last 2 weeks
$query->greaterThanEqualToRelativeTime(
    'date',
    '14 days ago'
);
$query->lessThanEqualToRelativeTime(
    'date',
    '0 days ago'
);

/* 
Units are as follows:

-day
-days

-hours
-hour
-hrs
-hr

-minutes
-minute
-mins
-min

-seconds
-second
-secs
-sec
*/

I plan on putting in some support for a singular now string for ease of dictating lessThan/greaterThan the current time. Please note that the times used are server times, and may be different from the current time or zone of your sdk. Take this into consideration, such as if your hosted service is running 8 hours ahead of your sdk for example.

This PR additionally updates package.json for testing purposes and adds package-lock.json into version control.

@codecov
Copy link

codecov bot commented Oct 30, 2017

Codecov Report

Merging #360 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #360      +/-   ##
==========================================
+ Coverage   98.93%   98.93%   +<.01%     
==========================================
  Files          35       35              
  Lines        3281     3301      +20     
==========================================
+ Hits         3246     3266      +20     
  Misses         35       35
Impacted Files Coverage Δ
src/Parse/ParseQuery.php 99.39% <100%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1964a4b...dc977fe. Read the comment docs.

@montymxb montymxb added this to the 1.4.0 milestone Oct 31, 2017
@montymxb montymxb merged commit 537ff77 into parse-community:master Oct 31, 2017
@montymxb montymxb deleted the relative-time-queries branch October 31, 2017 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant