Google Calendar API querying all-day events - date

I have an app that uses the Calendar v3 API to create, query, and modify all-day events on Google Calendar. These events look something like this when I create them:
{
summary: 'My Event",
start: { date: '2014-07-26' },
end: { date: '2014-07-26' }
}
So if I want to query all of such events between July 20th and July 26th, I send a query like this:
GET www.googleapis.com/calendar/v3/{calendarID}/events?timeMin=2014-07-20T00%3A00%3A00.000Z&timeMax=2014-07-26T00%3A00%3A00.000Z
In a more readable format, the parameters are:
timeMin:2014-07-20T00:00:00.000Z
timeMax:2014-07-26T00:00:00.000Z
However, this excludes all of the events with the date 2014-07-26, it gets only the events for the 20th to the 25th. In my parameters you can see that I have used setUTCHours(0) in order to have no time zone information.
If I remove the calls to setUTCHours(0) for the timeMin and timeMax parameters then I have the opposite problem, I get 7/21 through 7/26 and miss the events on 7/20. How can I reliably get all of the all-day events for the week in any time zone?

Just came across this myself. For filtering, the end time is exclusive while the start time is inclusive. See the events spec here. Presumably when you just specify a date and not a time, it treats it something like 00:00:00 UTC -- so not inclusive of that day. But that's just speculation on my part. Anyway, if you +1 to your end date it should work the way you expect it to.

I would ask for +1 day on both sides of the week and post-filter the events that are not interesting.

The problem was with how I was creating events. To create an all-day event on date 1, you should set the start to x and the end to x + 1 day.
var dateStringStart = dateToString(dateObj);
var dateObjEnd = new Date(dateObj.getTime() + (24 * 60 * 60 * 1000));
var dateStringEnd = dateToString(dateObjEnd);
gapi.client.request({
path: '/calendar/v3/calendars/' + id + '/events',
method: 'POST',
body: {
summary: name,
start: {
date: dateStringStart
},
end: {
date: dateStringEnd
}
},
callback: function(eventObj) {
// ...
}
});

Related

ExtJS: Date field writes the date one day back?

I'm using a 'Ext.form.field.Date' and on CRUD process it writes given date as one day back. I mean if I select 05 June 2018, it writes as 04 June 2018.
I've checked related model and widget itself but nothing seems weird! Why this could be?
Here is model statement and field;
Ext.define('MyApp.FooModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'mydatefld', type: 'date', dateReadFormat: 'c', dateWriteFormat: 'Y-m-d'},
//and implementation
Ext.define('MyApp.BaseDateFld', {
extend: 'Ext.form.field.Date',
xtype: 'basedatefld',
format: 'd.m.Y',
flex: 1,
labelAlign: 'right',
name: 'MyDate Fld',
fieldLabel: 'MyDate Fld',
bind: '{currRec.mydatefld}'
});
Each time saves date as on XHR request payload;
2018-06-05T21:00:00.000Z //But should be 2018-06-06T06:05:00.000Z
Update:
I've tried change dateWriteForm to 'Y-m-d H:i:s' and 'Y-m-d H:i' but still noting changes on payload and keep decrease one day and sets time to 21:00:00
As well tried to change compouter TS to some another as #Alexander adviced but nothing changed.
Update 2:
I've over come the current issue but really a very DRY solution, so not safe!
Below there is insertion method (update method is almost same as this) and formating the related date value on here, thusly became success.
Server accepting the date format for this field as Y-m-d, so I've stated dateWriteFormat on model and submitFormat on datefield as 'Y-m-d' but it keeps write the date value with timestamp.
When I check rec param on method it is as 2018-06-06T21:00:00.000Z(The TZ part shouldn't be here!). And store param changes the givin date one day off as 2018-06-05T21:00:00.000Z.
Still not sure why I can't convert/format through model or field.
Thanks for advices.
recInsertion: function (rec, store) {
store.getProxy().url = store.getProxy().api.create;
rec.data.givindate = Ext.Date.format(rec.data.mydate, 'Y-m-d'); //This is current solution to format date! Which is really not safe and will cause DRY.
Ext.Ajax.request({
url: store.proxy.url,
method: 'POST',
jsonData: JSON.stringify(rec.data),
callback: function (options, success, response) {
Ext.GlobalEvents.fireEvent('showspinner');
if (success) {
Ext.GlobalEvents.fireEvent('refreshList');
}
else
Ext.GlobalEvents.fireEvent('savefailed');
}
});
},

Mongoose or MongoDB removing 24 hours from date?

I have to be doing something wrong but I cannot figure out what it is. I currently have a date field in my application that has a value format of MMMM, D YYYY.
For this example, I am going to be using the date October 1, 2018.
In the application, the user selects October 1, 2018 which logs as
October 1, 2018
Later I convert this date into a savable date by using var docDate = new Date($('#insuranceExpiration').val()).toISOString(); which logs as
2018-10-01T04:00:00.000Z
I then add this to an object stringify it and send it to the server where I log the date and shows as
2018-10-01T04:00:00.000Z
I then use Mongoose to save this date to MongoDB but when I go to see the saved date I show
2018-09-30T04:00:00.000Z
I cannot figure out for the life of me why I am seeing a date 24 hours in the past from the date I choose. Below is the mongoose code to see if I am doing something wrong on that end.
app.post('/api/myDocuments/insuranceGeneral', function(req, res ) {
console.log(req.body.expires);
// prints 2018-10-01T04:00:00.000Z
InsuranceGeneral.findOneAndUpdate({
_id: req.rsaConPortal.id
}, {
$set: {
"documents.insurance.name": req.body.name,
"documents.insurance.expires": req.body.expires,
"documents.insurance.url": req.body.url,
"documents.insurance.uploadDate": req.body.uploadDate
}
}, function(err, doc) {
if (err) throw err;
res.send('Success');
});
});
Even if I use a standard javascript date object I can print this on the browswer log
Mon Oct 01 2018 00:00:00 GMT-0400 (Eastern Daylight Time)
This prints on the sever just before mongoose
2018-10-01T04:00:00.000Z
But this is the end result in mongodb
2018-09-30T04:00:00.000Z
I think you and your server in different timezone. And mongodb uses GMT. If you are not declaring time in your iso date, it is setting it's time as 00:00.000Z. So for GMT this is one day earlier. Simply you should convert your date to GMT, you can use moment or you can fix problem by subtraction offset from date like this:
var offset = new Date().getTimezoneOffset() * 60000;
var date = new Date(new Date($('#insuranceExpiration').val())) - offset).toISOString();
or with moment.js
var date = moment($('#insuranceExpiration').val()).tz('GMT').format('YYYY-MM-DD');

Rally: Date User Story is Defined

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

Best way to store and organize data in MongoDB

I have a users in MongoDB and each user has an interface allowing them to set their current state of hunger being a combination of "hungry", "not hungry", "famished", "starving", or "full"
Each user can enter a multiple options for any period of time. For example, one use case would be "in the morning, record how my hunger is" and the user can put "not hungry" and "full". They can record how their hunger is at any time in the day, and as many times as they want.
Should I store the data as single entries, and then group the data by a date in MongoDB later on when I need to show it in a UI? Or should I store the data as an array of the options the user selected along with a date?
It depends on your future queries, and you may want to do both. Disk space is cheaper than processing, and it's always best to double your disk space than double your queries.
If you're only going to map by date then you'll want to group all users/states by date. If you're only going to map by user then you'll want to group all dates/states by user. If you're going to query by both, you should just make two Collections to minimize processing. Definitely use an array for the hunger state in either case.
Example structure for date grouping:
{ date: '1494288000',
time-of-day: [
{ am: [
{ user: asdfas, hunger-state: [hungry, full] },
{ user: juhags, hunger-state: [full] }
],
pm: [
{ user: asdfas, hunger-state: [hungry, full] },
{ user: juhags, hunger-state: [full] }
]}]}
It depends on how you are going to access it. If you want to report on a user's last known state, then the array might be better:
{
user_id: '5358e4249611f4a65e3068ab',
timestamp: '2017-05-08T17:30:00.000Z',
hunger: ['HUNGRY','FAMISHED'],
}
The timestamps of multiple records might not align perfectly if you are passing in the output from new Date() (note the second record is 99 ms later):
{
user_id: '5358e4249611f4a65e3068ab',
timestamp: '2017-05-08T17:30:00.000Z',
hunger: 'HUNGRY',
}
{
user_id: '5358e4249611f4a65e3068ab',
timestamp: '2017-05-08T17:30:00.099Z',
hunger: ['FAMISHED',
}
You should probably look at your data model though and try to get a more deterministic state model. Maybe:
{
user_id: '5358e4249611f4a65e3068ab',
timestamp: '2017-05-08T17:30:00.000Z',
isHungry: true,
hunger: 'FAMISHED',
}

get records created within 24 hour in sails js

I want to fetch the Posts which are created within 24 hours in sails js. And I am using mongodb database. How do I get all those Posts which are created in past 24 hours.
You can create a date range that consists of 24 hours in the following manner.
Using the momentjs library, you can create a date with the extension methods subtract() and cast it to a JS Date with the toDate() method:
var start = moment().subtract(24, 'hours').toDate();
or with plain vanilla Date objects, create the date range as:
var now = new Date(),
start = new Date(now.getTime() - (24 * 60 * 60 * 1000));
Use the where() method to use the query the Posts model using the above date range query, given the field which holds the timestamp is called date:
Posts.find()
.where({ "date" : { ">": start } })
.exec(function (err, posts) {
if (err) throw err;
return res.json(posts);
});