I need to pick birth date and the condition is user must be older than 18 years and less than 100 years. How to set constraints for dijit.form.DateTextBox? Please anyone help me to do so.
try the following:
var test2 = new dijit.form.DateTextBox({
constraints: {
min: dojo.date.add(new Date(),"year",18),
max: dojo.date.add(new Date(),"year",100),
}
},document.createElement("div"));
Greetings, Simon
Require dojo/date and name the parameter in your require statement date.
Then do something like:
dateTextBox.set("constraints", {
min: date.add(new Date(), "year", 18),
max: date.add(new Date(), "year", 100)
});
Related
I am writing a program that needs to fetch user stories that are defined before day 3 of a release. Is there a way to find out what day a user story was set to the 'defined' state so that I could query that?
I looked through the Web Service API docs but I couldn't find anything that could help me, although I could have missed something.
This is the code I am using to get the 3rd day of a release:
var releaseStart = combobox.getRecord().get('ReleaseStartDate');
releaseStart.setDate(releaseStart.getDate()+3);
this._startDate = Rally.util.DateTime.toIsoString(releaseStart);
But I'm not sure how to relate this to the date a user story is defined.
If anyone could help it would be much appreciated!
You're right- this piece of data does not exist in the standard WSAPI. You can get it from LookbackAPI however. How about something like this to get started?
var releaseStart = combobox.getRecord().get('ReleaseStartDate');
var startDate = Rally.util.DateTime.add(releaseStart, 'day', 3);
var snapshotStore = Ext.create('Rally.data.lookback.SnapshotStore', {
context: {
workspace: this.getContext().getWorkspaceRef()
},
find: {
_ProjectHierarchy: this.getContext().getProject().ObjectID,
_TypeHierarchy: 'HierarchicalRequirement',
ScheduleState: {$gte: 'Defined'},
__At: startDate
},
sort: {
_UnformattedID: 1
},
fetch: ['FormattedID', 'Name', 'ScheduleState'],
limit: Infinity,
autoLoad: true,
listeners: {
load: function(store, records) {
//TODO: work with records here
}
}
});
More information on working with the Lookback API is here: https://help.rallydev.com/apps/2.1/doc/#!/guide/lookback_api
This Meteor server code tries to count all the records which are 4 months and newer with property size:'4', color:'white' but account all entires from any one user as one count, so no mater how many documents have been entered by the same user, the are all counted as one. but I am getting nothing in return. any ideas? thx
let date = new Date();
date.setMonth(date.getMonth() - 4);
let doc = UsageCol.aggregate([{
$match: {
createdAt: {
$gte: date,
$lte: new Date()
},
action: 'failBroadcast',
plate: plate
}
}, {
$group: {
_id: {
userId: "$userId"
},
count: {
$sum: 1
}
}
}]);
for (var i = 0; i < doc.length; i++) {
var obj = doc[i];
console.log(JSON.stringify(obj));
}
Alright I just wanted to clear some things up from this morning.
The only reason I recommended moment js was thinking we are storing the date in date type and there is no easy way to dynamically create date in UTC using java script date function
So now that we know you used Date.now() to save the dates, you don't need any moment js.
The correct syntax is
let dateToMillis = Date.now(); //The current millis from epoch.
let dateFrom = new Date(dateToMillis); // Use the current millis from epoch.
let dateFromMillis = dateFrom.setMonth(dateFrom.getMonth() - 4); // The millis 4 months ago from epoch.
Pass dateToMillis and dateFromMillis to aggregation query.
Looking to query against the date only anyone encountered this?
Sample code:
////MODEL
module.exports = {
attributes: {
date: {
type: 'date',
required: true
}
}
};
////CONTROLLER
var today = moment().toISOString();
var queryObj = { date: today };
var newDay = { date: today };
Day.findOrCreate(queryObj, newDay).exec(function(err, day) {
console.log(day)
});
Obviously this creates a new record on each refresh, as the iso string will change with each passing second.
Thanks for the help!
Instead of querying for a single date, you can query for a date range that includes all of today. First, you'll need to actually create values for that range--I whipped this up using Moment, but there's probably a better way:
var begin = moment(moment().format("YYYY-MM-DD")).toISOString();
var end = moment(moment().format("YYYY-MM-DD")).add(1, 'days').toISOString();
Then you can use query operators to search the range:
var queryObj = {date: {'>=': begin, '<': end}};
Day.findOrCreate(queryObj, newDay).exec(function(err, day) {
console.log(day)
});
As always, be mindful of time zone issues!
Trying to figure out how to do this. Basically I want to sort by Hour / Day / Month / Year of my submissions.
Each submission has a created field which contains a Mongoose Date object in the form of "created" : ISODate("2013-03-11T01:49:09.421Z"). Do I need to compare against this in the find() conditions?
Here is my current query (I'm wrapping it in a count for pagination purposes FWIW so just ignore that part):
getSubmissionCount({}, function(count) {
// Sort by the range
switch (range) {
case 'today':
range = now.getTime();
case 'week':
range = now.getTime() - 7;
case 'month':
range = now.getTime() - 31; // TODO: make this find the current month and # of days in it
case 'year':
range = now.getTime() - 365;
case 'default':
range = now.getTime();
}
Submission.find({
}).skip(skip)
.sort('score', 'descending')
.sort('created', 'descending')
.limit(limit)
.execFind(function(err, submissions) {
if (err) {
callback(err);
}
if (submissions) {
callback(null, submissions, count);
}
});
});
Can someone help me figure this out? With that current code it just gives me all submissions regardless of a time range, so I'm obviously not doing something properly
I think, you are looking $lt(Less than) and $gt(Greater Than) operators in MongoDB.
By using above operators the result can be queried according to time.
I am adding possible solution below.
var d = new Date(),
hour = d.getHours(),
min = d.getMinutes(),
month = d.getMonth(),
year = d.getFullYear(),
sec = d.getSeconds(),
day = d.getDate();
Submission.find({
/* First Case: Hour */
created: { $lt: new Date(), $gt: new Date(year+','+month+','+day+','+hour+','+min+','+sec) } // Get results from start of current hour to current time.
/* Second Case: Day */
created: { $lt: new Date(), $gt: new Date(year+','+month+','+day) } // Get results from start of current day to current time.
/* Third Case: Month */
created: { $lt: new Date(), $gt: new Date(year+','+month) } // Get results from start of current month to current time.
/* Fourth Case: Year */
created: { $lt: new Date(), $gt: new Date(year) } // Get results from start of current year to current time.
})
How can I sort the "days ago" formatted date in jqGrid ? When I sort the grid currently, it can't distinguish between "11 hours ago" and "1 days ago". So "1 day ago" is sorted on the top instead of "11 hours ago".
**Please refer this image of the grid.
My jqGrid has the following code. recommendationData is JSON. Posted column is the date.
$("#tblRecommendationList").jqGrid({
data: recommendationData,
datatype: 'local',
colModel: [
{ name: 'Title', label: 'Title', width: 210, resizable: true },
{ name: 'Channel', label: 'Content Type', width: 120, resizable: true },
{ name: 'StatusNumber', label: 'Status', width: 120, resizable: true,
formatter: GetStatusCode },
{ name: 'Posted', label: 'Posted', width: 120, resizable: true },
{ name: 'RecordId', label: 'RecordId', hidden: true }
],
loadtext: 'Loading...',
loadui: 'block',
emptyDataText: "No Recommendations to display",
shrinkToFit: true,
The date is passed in the following manner.
...
returnList =
(
from i in responseList
select new InQuiraRecommendation
{
StatusNumber = i.statusnumber,
Title = i.title,
Text = i.text,
Posted = GetDaysAgo(i.dateadded),
CaseNumber = i.casenumber,
Priority = i.priority,
Channel = i.channel,
RecordId = i.recordid,
}
).ToList();
}
return returnList;
}
GetDaysAgo( ) changes the "2012-09-13 07:00:00 Etc/GMT" date format to "Days ago" format.
The problem starts with the usage of datatype: 'local' with the data prepared on the server. If you would uses datatype: 'json' the server would be responsible for sorting of the data and you could just returns correctly sorted data to jqGrid.
Another way would be to implement GetDaysAgo method, which converts dates posted back in ISO 8601 format to texts like "11 hours ago" or "1 days ago", on the client side as JavaScript code. So you can use custom formatter (and unformatter) to display the data.
One more option is to define your custom sorttype property for 'Posted' column defined as function. The function could returns for example the number of hours which will be used instead of texts "11 hours ago" or "1 days ago" for sorting by the column.
Here is the first reference to custom sorting and here you will find some code example which could help you. You can simplify the implementation of custom sorting (implementation of sorttype as function) if you would create hidden column with sortable string (ISO 8601 for example). Inside of sorttype function you have access to any other data of the row per the second parameter of sorttype (see here for more information). In the way you can just return ISO 8601 representation of 'Posted' (from hidden column) as the result of sorttype function.
I'd add 'dateadded' to your InQuiraRecommendation class and include that as a hidden field on your grid, then use that as your sort column.