Comparing #Now to a Date/Time field? - xpages

How do I compare #Now to a data / time value in a document? This is what I have
var ProjectActiveTo:NotesDateTime = doc.getItemValueDateTimeArray("ProjectActiveTo")[0];
var ProjectExpired;
var d1:Date = #Now();
if (d1 > ProjectActiveTo.toJavaDate())
{
dBar.info("Today: " + d1 + " > " + ProjectActiveTo.toJavaDate());
ProjectExpired = true;
}
else
{
dBar.info("Today: " + d1 + " < " + ProjectActiveTo.toJavaDate());
ProjectExpired = false;
}
But this always seems to return false. I printed out some diagnostic messages.
Today: 1/18/13 6:02 PM < 1/20/01 5:00 PM
Obviously today is greater than 1/20/01 but this is the result of my test. Why?
I have done some searching and saw that the compare member function might be used but it returns an error for me and compare is not in the intelisense (or whatever Lotus calls it) in the design editor.

Found this little snippet on line - it should point you in the right direction
var doc:NotesDocument = varRowView.getDocument();
var d:NotesDateTime = doc.getItemValue("BidDueDate")[0];
var t:NotesDateTime = session.createDateTime("Today");
if (d.timeDifference(t) > 0 ) {
return "Overdue";
}else{
return "";
}

Related

convert my string to AM or PM hour in ActionScript 3

I've got a String variable for my time :
var $myTime:String;
//Some calculation
trace(myTime);
// Result is : 14:25 (for example)
I'm looking for a way to convert this string ("14:25" in this example) to a simple AM / PM format.
So in this example it would be, for example, 2 PM
Any idea how I can simply do that ?
You can use DateFormatter class to set your wished pattern.
You can write your code as follow:
var df:DateFormatter = new DateFormatter();
df.formatString = "YYYY-MM-DD L:NN:SS";
df.format(myTime);
Where L is HOUR with PM/AM; NN are the minutes SS seconds.
You can see the complete guide, about DateFormatter pattern, here
var myTime:Date = new Date();
var timeString:String;
if (myTime.getHours() > 12)
{
timeString = String((myTime.getHours() - 12) + ":" + myTime.getMinutes() + " PM");
}
if (myTime.getHours() == 12)
{
timeString = String(myTime.getHours() + ":" + myTime.getMinutes() + " PM");
}
if (myTime.getHours() < 12)
{
timeString = String(myTime.getHours() + ":" + myTime.getMinutes() + " AM");
}
trace(timeString);
That should do the trick.

Function doesn't execute inside loop

I'm making a simple terminal calculator but for some reason a function isn't executing inside a while loop but executes outside the loop.
Given this input: ((1 + 2) + (3 + 4))
It should output:10
But gets stuck in an infinite loop because it doesn't replace the innermost expressions with their result.
The function that doesn't execute is s.replace(basicOp, answer);
Here is a snippet of the problem:
public static function processInput(s:String):String
{
var result:Null<Float> = parseNumber(s);
if (result != null)
{
return Std.string(result);
}
var closeParPos:Int = 0;
var openParPos:Int = 0;
var basicOp:String;
var answer:String = "";
// ERROR HERE
while (Std.string(answer) != s)
{
closeParPos = s.indexOf(")");
openParPos = s.lastIndexOf("(", closeParPos);
basicOp = s.substring(openParPos, closeParPos + 1);
answer = processBasicOp(basicOp);
// This isn't executed
s.replace(basicOp, answer);
trace("Input: " + s + " basicOp: " + basicOp + " Answer: " + answer);
}
return (result == null)? "": Std.string(result);
}
All the code is here just run make test
The input syntax is: ([number] [operator] [number]) or ([operator] [number])
There must be a single space between number and operators.
There shouldn't be any space between numbers and parenthesis
Supported operations:
+ - / *
% (remainder),
div (quotient),
sqr (square),
sqroot (square root),
sin cos tan (in degrees, bugged)
fact (factorial)
It isn't completed yet, there may be other problems, but this problem prevents me from advancing.
Can someone help me find the solution?
Thank you.
I can't actually get this to run, but StringTools.replace() doesn't modify the string in-place.
Try changing s.replace(basicOp, answer); to s = s.replace(basicOp, answer);

XPages typeahead takes too long

When we try typeahead with ftSearch , it takes too long to complete (to be shown on the screen). ftsearch finishes at the same time
[0D88:000B-0B44] 30.12.2015 10:03:06 HTTP JVM: Start= 30.12.2015 10:03
[0D88:000B-0B44] 30.12.2015 10:03:06 HTTP JVM: Finish= 30.12.2015 10:03
But in the inputbox which has typeahead properties results return more then 5 seconds. I mean It takes too long.
is there any suggestion how to decrease the time
'fldDefName = inthe inputbox there is a option for ftSearch named "Var" colNumber = Column Number for results. I generally user [0]
function getTypeAheadList(vName,frmName,fldName,fldDefName,colNumber)
{
var searchView:NotesView = database.getView(vName);'
var query = "(FIELD Form CONTAINS "+ frmName + " AND FIELD " + fldName + " CONTAINS *" + fldDefName +"*)";
print("Query= "+query);
var searchOutput:Array = ["å","åå"];
var hits = searchView.FTSearch(query);
var entries = searchView.getAllEntries();
var entry = entries.getFirstEntry();
for (i=0; i<hits; i++)
{
searchOutput.push(entry.getColumnValues()[colNumber]);
entry = entries.getNextEntry();
}
searchOutput.sort();
var result ="<ul><li><span class='informal'></span></li>";
var limit = Math.min(hits,50);
for (j=0; j<limit; j++)
{
var name = searchOutput[j].toString();
var start = name.indexOfIgnoreCase(lupkey)
var stop = start + lupkey.length;
name = name.insert("</b>",stop).insert("<b>",start);
result += "<li>" + name + "</li>";
}
result += "</ul>";
return result;
Reduce the number of docs that will be returned by FTSearch to 50 with
var hits = searchView.FTSearch(query, 50);
Right now the search result might contain e.g. 5000 docs and it takes time to push them into searchOutput and to sort. You reduce the hints afterwards to 50 anyway...

Search in view results with multible Fields Xpages

I have tried several times to enter a date range into the Search in view.
The search string i put into Search in view is as follow.
compositeData.Operasjon = "ST-MOD"
" FIELD OprPlanGruppe_1 = " + compositeData.Operasjon + " AND FIELD OprDato_1 = " +
dates.substring(0, dates.length() - 1);
The result is that only the last key value pair (FIELD OprDato_1 = 11.02.2014) is used to filter
The hole code is below:
var idag:java.util.Date = new java.util.Date();
var cal:java.util.Calendar =java.util.Calendar.getInstance();
var dateFormat:java.text.SimpleDateFormat = new java.text.SimpleDateFormat("dd.MM.yyyy");
cal.set(java.util.Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
cal.clear(java.util.Calendar.MINUTE);
cal.clear(java.util.Calendar.SECOND);
cal.clear(java.util.Calendar.MILLISECOND);
var dates = "";
var i;
for(i = 0; i < 7; i++){
cal.set(java.util.Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek() + i);
dates += dateFormat.format(cal.getTime()) + ",";
}
dates = dates.replace("undefined", "");
return " field OprPlanGruppe_1 = " + compositeData.Operasjon + " AND FIELD OprDato_1 = " + dates.substring(0, dates.length() - 1);
Is there any possibilities to add more than one value after Field in the filter query?
Ex: FIELD OprDato1 = 10.02.2014,11.02.2014
You want to show all documents in view which have in field "OprDato_1" a date that is within the current week. You use the "Search in view results" property of xp:viewPanel. It uses full text search and has to have the syntax of full text search. You can compare dates with ">=" and "<=". So, an easy way to look for dates in a certain date range is
FIELD OprDato_1 >= 10.02.2014 AND FIELD OprDato_1 <= 16.02.2014
or shorter as
[OprDato_1] >= 10.02.2014 AND [OprDato_1] <= 16.02.2014
Your code for calculating the search string would look like this:
var cal:java.util.Calendar =java.util.Calendar.getInstance();
var dateFormat:java.text.SimpleDateFormat = new java.text.SimpleDateFormat("dd.MM.yyyy");
cal.set(java.util.Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
var firstDate = dateFormat.format(cal.getTime());
cal.set(java.util.Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek() + 6);
var lastDate = dateFormat.format(cal.getTime());
return "FIELD OprPlanGruppe_1 = " + compositeData.Operasjon +
" AND FIELD OprDato_1 >= " + firstDate +
" AND FIELD OprDato_1 <= " + lastDate
This code calculates the date range for current week. You are free to set cal to any other date and date range would then be the week of this date.

Permission/Deny Mask in SharePoint

I have a question regarding SharePoint permission masks. In SharePoint it is possible to set the grant/deny rights using masks. Details are given the following article.
http://msdn.microsoft.com/en-us/library/dd304243(PROT.13).aspx
My question is when we have a permission/deny mask.
For example if you deny “ViewItem” permission using the central-admin, you will get 4611686844973976575 as the deny mask. This permission masks is computed by aping | to several individual permission masks.
So is it possible to extract individual permission masks which are used to calculate permission mask such as 4611686844973976575?
Thanks.
If you do a logical AND operation on a value such as 0x0000000000000001 for "ViewListItems" which is contained in the mask, then you will get the value itself (or 1). If you do a logical AND on a value not in that mask, like the "UseClientIntegration" value of 0x0000001000000000, then you will get a zero (0). This is something you can even test via the scientific mode of the Windows calculator app -- perhaps first converting the mask to hex, such as taking your example of 4611686844973976575 from base 10 to 400000C072040BFF in hex (base 16).
To extract all values from the mask, you would have to test the initial value against all possible values. If all known permission values are documented on that page, then the answer to your question is yes. I don't know which language you may want to accomplish this, but the basic idea in C# is:
bool CheckMask( long Mask, long TestPermission ) {
return (Mask && TestPermission) > 0;
}
long mask = 4611686844973976575;
const long ViewListItems = 0x0000000000000001;
bool HasPermission_ViewListItems = CheckMask(mask, ViewListItems);
// HasPermission_ViewListItems is true
const long UseClientIntegration = 0x0000001000000000;
bool HasPermission_UseClientIntegration = CheckMask(mask, UseClientIntegration);
// HasPermission_UseClientIntegration is false
I made this javascript sample thanks to #zanlok answer
I used JQuery, SPServices js (http://spservices.codeplex.com/)
and this link for the masks codes
http://msdn.microsoft.com/en-us/library/dd304243%28PROT.13%29.aspx
I Hope this helps you, I did this because I was needing it also, however it may also help others.
You need to replace the divid with the value of the control you want to place the html, and the LIST NAME HERE with the name of the list.
The script will spit everyone that has access to a list, and say if they can read, add, change and delete things. Hopes this helps you.
$('#divid').html('Working...').SPServices({
operation: "GetPermissionCollection",
objectName: 'LIST NAME HERE',
objectType: "List",
completefunc: function (xData, Status) {
var out = "<ul>";
$(xData.responseXML).find("Permission").each(function () {
if ($(this).attr("MemberIsUser") === "True") {
out += "<li>User: " + $(this).attr("UserLogin") + "</li>";
} else {
out += "<li>Group: " + $(this).attr("GroupName") + "</li>";
}
var readmask = 0x0000000000000001;
var addmask = 0x0000000000000002;
var editmask = 0x0000000000000004;
var deletemask = 0x0000000000000008;
out += "<li>Mask: " + $(this).attr("Mask") + "</li>";
var canread = readmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canadd = addmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var canedit = editmask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
var candelete = deletemask & $(this).attr("Mask").toString(16) > 0 ? "Yes" : "No";
out += "<li>Can Read: " + canread + "</li>";
out += "<li>Can Add: " + canadd + "</li>";
out += "<li>Can Edit: " + canedit + "</li>";
out += "<li>Can Delete: " + candelete + "</li>";
});
out += "</ul>";
$('divid').html(out);
}
});

Resources