1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>JSDoc: Source: lib/model/search/time.js</title>
|
6 |
|
7 | <script src="scripts/prettify/prettify.js"> </script>
|
8 | <script src="scripts/prettify/lang-css.js"> </script>
|
9 | |
10 |
|
11 |
|
12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
14 | </head>
|
15 |
|
16 | <body>
|
17 |
|
18 | <div id="main">
|
19 |
|
20 | <h1 class="page-title">Source: lib/model/search/time.js</h1>
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | <section>
|
28 | <article>
|
29 | <pre class="prettyprint source linenums"><code>var util = require('./util');
|
30 | var libUtil = require('../../util');
|
31 |
|
32 | /**
|
33 | {
|
34 | "timerange": true,
|
35 | "timerangefrom": 1396859660,
|
36 | "timerangeto": 1396859660,
|
37 | }
|
38 |
|
39 | {
|
40 | time: {
|
41 | from: time
|
42 | to: time
|
43 | }
|
44 | }
|
45 | */
|
46 |
|
47 | module.exports = function (params, query) {
|
48 | if(!params) return;
|
49 |
|
50 | query.timerange = true;
|
51 |
|
52 | var hasFrom = util.hasProp(params, "from"),
|
53 | hasTo = util.hasProp(params, "to");
|
54 |
|
55 | if(!hasFrom && !hasTo) {
|
56 | throw new Error("At least one of `from` or `to` properties has to be provided for time range search");
|
57 | }
|
58 |
|
59 | // set defaults
|
60 | // if from is not set, set to epoch
|
61 | params.from = params.from || (new Date(0));
|
62 | // if to is not set, set to now
|
63 | params.to = params.to || (new Date());
|
64 |
|
65 | if(hasFrom) {
|
66 | var timeFrom = libUtil.parseDate(params.from);
|
67 | query.timerangefrom = libUtil.toUNIX(timeFrom);
|
68 | }
|
69 |
|
70 | if(hasTo) {
|
71 | var timeTo = libUtil.parseDate(params.to);
|
72 | query.timerangeto = libUtil.toUNIX(timeTo);
|
73 | }
|
74 |
|
75 | };
|
76 | </code></pre>
|
77 | </article>
|
78 | </section>
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | </div>
|
84 |
|
85 | <nav>
|
86 | <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Action.html">Action</a></li><li><a href="Channel.html">Channel</a></li><li><a href="Client.html">Client</a></li><li><a href="Raptor.html">Raptor</a></li><li><a href="RecordSet.html">RecordSet</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="ServiceObject.html">ServiceObject</a></li><li><a href="Stream.html">Stream</a></li><li><a href="User.html">User</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Container">Container</a></li></ul>
|
87 | </nav>
|
88 |
|
89 | <br class="clear">
|
90 |
|
91 | <footer>
|
92 | Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.2</a> on Wed Nov 02 2016 11:15:06 GMT+0100 (CET)
|
93 | </footer>
|
94 |
|
95 | <script> prettyPrint(); </script>
|
96 | <script src="scripts/linenumber.js"> </script>
|
97 | </body>
|
98 | </html>
|