I'm using the JavaScript library datejs and in particularly the TimeSpan class.
I've got it all working great for one TimeSpan. However I need it to add together the results of multiple TimeSpans on the page. My code is below:
var monTimeSpan = new TimeSpan(Date.parse($("#monFinish").val()) - Date.parse($("#monStart").val()))
var tueTimeSpan = new TimeSpan(Date.parse($("#tueFinish").val()) - Date.parse($("#tueStart").val()))
These work great but I need to add the result of the Tuesday TimeSpan to the Monday one.
Any help would be great.
Thanks
The TimeSpan object includes the .add() function.
The following sample demonstrates adding two TimeSpan objects together.
Example
var t1 = new TimeSpan(Date.today().add(5).days() - Date.today());
var t2 = new TimeSpan(Date.today().add(10).days() - Date.today());
var total = t1.add(t2);
total.days // 15
Related
I am new to nodejs, and I am trying to get the difference between 2 times, but I get a different value.
here is my code :
var now = moment(Suivi.FI);
var then = moment(Suivi.DI);
var TA = moment(moment.duration(then.diff(now))).format("hh:mm");
as a result i get:
sql": "Insert into suivi(date, equipement, project, shift, description, Action, user, DA, DI, FI,TA) values('','','','','','','','','','','12:00')"
I tried to test with a simple date but I got the same value.
what am I missing? what should I do.?
you can use .format("hh:mm")
for simple time differnce:
var TA = now.diff(then);
this will give you more flexibility for formating (see docs):
var TA = moment.duration(now.diff(then));
I'm trying to add new names to the address book programmatically but I'm getting the following error:
[TypeError] Exception occurred calling method NotesDocument.replaceItemValue(string, Array)
Unknown or unsupported object type in Vector
Code snippet below:
var addressBook = session.getDatabase("","names.nsf");
var gView:NotesView = addressBook.getView("($VIMGroups)");
var gDoc:NotesDocument = gView.getDocumentByKey("groupName", true);
var newg:java.util.Vector = [];
var mems:java.util.Vector = new Array(gDoc.getItemValue('Members'));
newg.push(mems);
var newNames:java.util.Vector = new Array(getComponent("NewMems").getValue());
newg.push(newNames);
gDoc.replaceItemValue("Members", newg);
gDoc.save();
Adding a single user works fine, but then it does not save users in the required canonical format below:
CN=John Doe/O=Org
Instead it is saved in the original format below:
John Doe/Org
I look forward to your suggestions. Thanks.
You can't store an Array in a field. Make newg a java.util.Vector instead and integrate with that.
For OpenNTF Domino API the team wrote a lot of code to auto-convert to Vectors, which may cover Arrays.
Don't use an Array (which is a JS thing). Initialize it as a Vector.
var newg:java.util.Vector = new java.util.Vectory();
Then look up the Vector methods to see how to add to that vector. Not sure if you will have to convert the names using the Name method but I would store them as "CN=Joe Smith/O=Test Org" to be sure you got the right format.
I was able to solve the issue using a forloop to loop through the list and push it into a newly created array. Using the forloop seems to make the difference.
var newg = [];
var group = new Array(getComponent("NewMems").getValue()), lenGA = group.length;
for(i = 0; i < lenGA; i++){
newg.push(group[i]);
}
gDoc.replaceItemValue("Members", newg);
gDoc.save();
An explanation about this behaviour will be appreciated.
I need to save the date value of a particular action into the local storage from a resource file. The date value should be compared with the current date in the background in regular intervals. the code i am using in the resource file to store the date value is
var x = new Date();
var enableDate = x.getFullYear()+"-"+(x.getMonth()+1)+"-"+x.getDate();
appAPI.db.async.set("ext_enable_date",enableDate);
and the code i used to retrieve the saved date from 'background.js' is
var enDate = appAPI.db.get("ext_enable_date");
But i get null value in 'enDate'. How can i get it correct? Any help would be appreciated.
The Crossrider framework provides 2 types of local storage, as follows:
appAPI.db - a synchronous database for saving small data (integers, booleans, and short strings of approximately 10 characters)
appAPI.db.async - an asynchronous database for saving larger data
The storages are completely distinct and one cannot access the other. Hence, the problem with code is that it saves the date using an asynchronous method (async.set) and then tries to retrieve it using a synchronous method (get).
As your data is small, simply resolve the issue by using the synchronous methods as follows:
var x = new Date();
var enableDate = x.getFullYear()+"-"+(x.getMonth()+1)+"-"+x.getDate();
appAPI.db.set("ext_enable_date",enableDate);
var enDate = appAPI.db.get("ext_enable_date");
[Disclosure: I am a Crossrider employee]
I am confused about how the search function works in the Spotify API. Their example is like this:
var sp = getSpotifyApi();
var models = sp.require('$api/models');
var search = new models.Search('Rihanna');
search.localResults = models.LOCALSEARCHRESULTS.APPEND;
var searchHTML = document.getElementById('results');
search.observe(models.EVENT.CHANGE, function() {
var results = search.tracks;
var fragment = document.createDocumentFragment();
for (var i=0; i<results.length; i++){
var link = document.createElement('li');
var a = document.createElement('a');
a.href = results[i].uri;
link.appendChild(a);
a.innerHTML = results[i].name;
fragment.appendChild(link);
}
searchHTML.appendChild(fragment);
});
search.appendNext();
So, I guess that calling appendNext() initiates the search, and the inner function is called when it has results? But the results are limited to a certain number (default 50) of the total. How do you get the rest? Do you call appendNext() again recursively from inside the callback? Also, does that mean that after you do that, your list includes the original results, or are the original results replaced? Anyone know of an example that searches through all available results?
Also they mention that if the search is running, appendNext() does nothing. So how do you gracefully wait until the current search is complete before getting the next 'page'?
Their documentation is terrible, IMHO. Say you have 1000 search results total from the server. And say I want to see results 900-1000. Have I got to keep calling AppendNext over and over until I get to 900?
Thanks
Bob
There is no pagination when using the Search functionality built in the Spotify Apps API. You can increase the number of results so it returns more than 50 results (see the Search page in the documentation), although the amount is limited (it seems to be 200 tracks at the moment).
There is an alternative way, which is performing requests to the Web API instead.
I am using Fluent NHibernate for my ORM. In doing so I am trying to use the NHibernate LINQ syntax to fetch a set of data with the power of LINQ. The code I have works and executes correctly with the exception being that a timeout is thrown if it takes longer than roughly 30 seconds to run. The question I have is how do I extend the default 30 second timeout for LINQ statements via NHibernate?
I have already seen the posts here, here, and here but the first two refer to setting the DataContext's Timeout property, which does not apply here, and the third refers to setting the timeout in XML, which also does not apply because I am using Fluent NHibernate to generate the XML on the fly. Not only that but the post is 2 years old and Fluent NHibernate has changed since.
With the ICriteria objects and even HQL I can specify the timeout, however that is not the goal here. I would like to know how to set that same timeout and use LINQ.
Example code:
using (var session = SessionFactory.OpenSession())
using (var transaction = session.BeginTransaction())
{
var query = (from mem in session.Query<Member>()
select mem);
query = query.Where({where statement});
int start = (currentPage - 1) * max);
if (start > 0)
query = query.Skip(start).Take(max);
else
query = query.Take(max);
var list = query.ToList();
transaction.Commit();
return list;
}
This code (where statement does not matter) works for all purposes except where a timeout occurs.
Any help is appreciated. Thanks in advance!
I ended up setting the command timeout for the Configuration for Fluent NHibernate. The downside to this is that it sets the timeout for ALL of my data access calls and not just the one.
Example code:
.ExposeConfiguration(c => c.SetProperty("command_timeout", (TimeSpan.FromMinutes(10).TotalSeconds).ToString()))
I found this suggestion from this website.
Nhibernate has extended the IQueryable and added a few methods https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Linq/LinqExtensionMethods.cs
var query = (from c in Session.Query<Puppy>()).Timeout(12);
or
var query = (from c in Session.Query<Puppy>());
query.Timeout(456);
I've just spent fair amount of time fighting with this and hopefully this will save someone else some time.
You should use the .Timeout(120) method call at the very last moment to make sure it is used. TBH I'm not 100% sure on why this is but here are some examples:
WILL WORK
query = query.Where(x => x.Id = 123);
var result = query.Timeout(120).ToList();
DOESN'T WORK
query.Timeout(120);
query = query.Where(x => x.Id = 123);
var result = query.ToList();
If done like the second (DOESN'T WORK) example, it seems to fall back to the default System.Transaction.TransactionManager.DefaultTimeout.
Just in case anyone is still looking for this and finds this old thread too...
Query.Timeout is deprecated.
You should use WithOptions instead:
.WithOptions(o => o.SetTimeout(databaseTimeoutInSeconds))