x pages Question: calculate working day Error - xpages

I try use computed field to calculate leave and working days. The error form show as below
script to count the working days
var nDateStart = session.createDateTime(document1.getValue("StartDate")).toJavaDate();
var nDateEnd = session.createDateTime(document1.getValue("EndDate")).toJavaDate();
var syear = #Year(nDateStart)
var smth = #Month(nDateStart)
var sday = #Day(nDateStart)
var startdate = #Date(syear,smth,sday)
var eyear = #Year(nDateEnd)
var emth = #Month(nDateEnd)
var eday = #Day(nDateEnd)
var enddate = #Date(eyear,emth,eday)
var weekends = "1:7"; //assuming your weekend is Saturday and Sunday
var holidays = "#Date(2019;8;12):#Date(2019;12;25)"; // assuming your holiday is 12 August and 25th December
var formula = "#BusinessDays(" + startdate + ";" + enddate + ";" + weekends + ";" + holidays + ")";
return session.evaluate(formula);

Date/time constants in Lotus formula language are enclosed in square brackets, which you can clearly see in the documentation for #BusinessDays. Try this:
var formula = "#BusinessDays([" + startdate + "];[" + enddate + "];" + weekends + ";[" + holidays + "])";
return session.evaluate(formula);

You need to calculate a valid formula before you can submit it to session.evaluate. The string you submit isn’t a valid formula. E.g the your parameter is just an unquoted string.
Remove the startdate and enddate and replace it with something like ”#Date(“+syear+”;”+smonth+”;”+”;”+sday+”)” that should give you the formula you seek.

Related

Generating bulk dates

I wanted to ask if anyone knows a way of generating bulk dates. I want to know about how can I generate all of the dates and times between 20130631_0000 till 20151231_2359
The month limit is 0-12
The day limit is 0-31
and the part you see after underscore is hour and minute, the hour limit is 00 till 23 and the minute is from 00 till 59. It's basically YYYYMMDD_HHMM
Few examples:
20130810_1154, 20140103_2357, 20150722_1049, 20140103_2358, 20140103_2359, 20140104_0000, 20140104_0001, 20140105_1159, 20140105_1200
If you simply want to print each date to the console:
let date = new Date(2013,6,31,0,0);
const endDate = new Date(2015,12,31,23,59);
const padWithZero = num => num.toString().padStart(2, '0');
while (date <= endDate) {
const year = date.getFullYear();
const month = padWithZero(date.getMonth()+1);
const day = padWithZero(date.getDate());
const hour = padWithZero(date.getHours());
const minute = padWithZero(date.getMinutes());
console.log(`${year}${month}${day}_${hour}${minute}`)
date = new Date(date.getTime() + 60000)
}
Try this
function convertStringToDate(date){
var year = date.substring(0,4)
var month = date.substring(4,6)
var day = date.substring(6,8)
var hour = date.substring(9,11)
var minute = date.substring(11,13)
return new Date(parseInt(year), parseInt(month), parseInt(day), parseInt(hour), parseInt(minute) )
}
function addMinute(date){
var new_date = date;
new_date.setMinutes(date.getMinutes()+1)
return new_date
}
function getDatesBetween(start_date_str, end_date_str){
var start_date = convertStringToDate(start_date_str)
var end_date = convertStringToDate(end_date_str)
dates = []
date = start_date
while(date.getTime() !== end_date.getTime()){
dates.push(new Date(date))
date = addMinute(date)
}
dates.push(end_date)
return dates
}
function pad (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
function convertDateToString(date){
var year = date.getFullYear().toString()
var month = pad(date.getMonth().toString(),2)
var day = pad(date.getDay().toString(),2)
var hour = pad(date.getHours().toString(),2)
var minutes = pad(date.getMinutes().toString(),2)
return year + month + day + "_" + hour + minutes
}
var start_date_str = "20130620_1224"
var end_date_str = "20130621 1224"
dates = getDatesBetween(start_date_str, end_date_str)
formatted_dates = dates.map(convertDateToString)
console.log(dates.length)
console.log(dates[dates.length-1])
console.log(formatted_dates.length)
console.log(formatted_dates[dates.length-1])

Individual start date per month

together
how do I get it in PowerPivot or as Dax formula out that for my internal / individual months the beginning of the month from 31.120.2018 for January 2019 receive?
So, that I get the January in the PowerPivot calendar table already from 31.12.2018 and then in the 4-4-5 weeks cycle?
So
31.12.2018 + 28 days = January
31.12.2018 + (28 days * 2) = February
31.12.2018 + (28 days * 2) + 7 days = March
Does anyone have an idea?
Best Regards
First I create a calendar table, this is the simple part, I took a random start and end for testing:
CalendarDates = CALENDAR(DATE(2012;12;20);DATE(2021;1;5))
Then I added the column WeekNumber, this is to the greorgian calendar. A bit complicated because microsoft simply starts counting with 1 on the first of january..
WeekNumber =
var wNrfirstDayJanNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;1);2)
var fullWeekNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;7);2) = 1 //If day 7 of week is still first week, its a full week
var wNr31Dex = WEEKNUM(DATE(CalendarDates[Date].[Year];12;31);2)
var wNr31DexPrevYear = WEEKNUM(DATE(CalendarDates[Date].[Year]-1;12;31);2)
var wNr = WEEKNUM(CalendarDates[Date];2)
var pbi4JanWeekNrNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;4);2)
var pbi4JanWeekNr = WEEKNUM(DATE(CalendarDates[Date].[Year];1;4);2)
var wNrComp = if (pbi4JanWeekNr =2; wNr - 1; wNr)
return if(NOT(fullWeekNextYear) && wNr = wNr31Dex;IF(pbi4JanWeekNrNextYear = 2; wNr31Dex;1);if(wNrComp = 0; wNr31DexPrevYear; wNrComp))
last step is to create the Month based on the week number:
Month =
var quater = FLOOR((CalendarDates[WeekNumber] - 1)/13; 1)
var quarterWeek = MOD(CalendarDates[WeekNumber] - 1 - (quater*13);13)
var monthNr = FLOOR(quarterWeek/4;1)
var month445 = if (monthNr = 3; 2; monthNr) + quater * 3 + 1
return if (month445 = 13; 12;month445)
Note: I corrected week 53 in the last quarter so it becomes 4-4-6. You need to do your own math if you want it different.
End result:

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.

Trying to calculate the end of the next day in node.js

I'm trying to calculate the end of the next day for any given date as an expiry date.
So if the input is eg 10/26/2013 16:36:46 then I'd like to get 10/27/2013 23:59:59 and 7/31/2013 16:36:46 would give me 8/1/2013 23:59:59
It gets obviously difficult with leap years and when the next day is a new month. So I tried to use the dateParse function which gives me a number that I can easily add 86400000 (full day in milliseconds) and then I want to use basically the reverse of dateParse (turn a number into a date object) so that I can then take out the date component and replace the time component with 23:59:59
Here's my code which doesn't work - setTime doesn't seem to be the right function and makes my next_day variable "undefined"
var next_day = call_start.dateParse + 86400000; // adding a full day to it
next_day = next_day.setTime;
var day = next_day.getDate;
day = (day < 10 ? "0" : "") + day;
var month = next_day.getMonth + 1;
month = (month < 10 ? "0" : "") + month;
var year = next_day.getFullYear;
var hour = 23;
var min = 59;
var sec = 59;
var expiry = year + ":" + month + ":" + day + ":" + hour + ":" + min + ":" + sec;
console.log ('Streak expires at: ' + expiry);
You can use the set* functions to modify the date:
var date = new Date('7/31/2013 16:36:46');
date.setDate(date.getDate() + 1);
date.setHours(23);
date.setMinutes(59);
date.setSeconds(59);
console.log(date);
// Thu Aug 01 2013 23:59:59 GMT+0200 (CEST)

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.

Resources