Difference between datepickers except sundays in infopath - infopath-2007

How to get the no of days between two date picker controls in info path except sundays?
If It is possible let me know.
Thanks in advance.........

Using custom code you can do it easily. In this case I'm calculating the number of days (except Sundays) between a given date and today's date.
var navigator = this.MainDataSource.CreateNavigator();
string startDate = navigator.SelectSingleNode("/my:myFields/my:date_start", NamespaceManager).Value;
DateTime startDateTime = DateTime.ParseExact(startDate, "yyyy-MM-dd", null);
DateTime today = DateTime.Today;
int count = 0;
while (startDateTime > today)
{
today = today.AddDays(1);
if (today.DayOfWeek != DayOfWeek.Sunday)
{
count++;
}
}
I hope it helps

Related

How do you compare selector attributes in Testcafe?

I'm trying to compare the date of videos on a webpage to today's date. If the difference between the two dates is more than X days, report back as false.
The videos on the webpage have a tag in them which uses the format yyyy-mm-dd
I've got a selector set up to find the videos const videoDate = Selector('OPTA-video').withAttribute('data-secondary-time')
Now how do I set a variable to today's date and compare the two? I'm completely stuck!
I was using Katalon Studio before and here's the groovy script that did the same job:
String videoDate = WebUI.getAttribute(findTestObject('OPTA-video'), 'data-secondary_time')
LocalDate todaysDate = LocalDate.now()
LocalDate videoDateParsed = LocalDate.parse(videoDate, dtf)
if (ChronoUnit.DAYS.between(videoDateParsed, todaysDate) > 1) {
KeywordUtil.markFailed('The videos are 2+ days old.')
} else {
KeywordUtil.logInfo('The videos are up to date.')
}
You can use the getAttribute TestCafe method to access an attribute value. Then, parse the attribute value into the JavaScript Date object:
String videoDate = Selector('OPTA-video').getAttribute('data-secondary-time');
Date videoDateParsed = Date.parse(videoDate);
Date todaysDate = Date.now()
...
In the following thread you can find how to compare Date objects.
This is one of the scripts that I am using.
//getting your XPath test value into a string
String ann_time =
WebUI.getText(findTestObject("ObjectRepository/navigateTOElement/announcements_date"))
//converting time to simple date format
SimpleDateFormat sdf = new SimpleDateFormat('HH:mm')
Date sdf_anntime = sdf.parse(new String(ann_time))
//getting Current time
SimpleDateFormat dateFormatGmt = new SimpleDateFormat('HH:mm')
dateFormatGmt.setTimeZone(TimeZone.getTimeZone('GMT'))
SimpleDateFormat dateFormatLocal = new SimpleDateFormat('HH:mm')
currDate = dateFormatLocal.parse(dateFormatGmt.format(new Date()))
// time gap in long format
long duration = currDate.getTime() - sdf_anntime.getTime()
//time gap to mins
long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration)
//compare time gap with globale variable
if (diffInMinutes < GlobalVariable.News_updated_time) {
log.logInfo("system is getting updated,last updated "+ diffInMinutes + "min ago")
} else {
CustomKeywords.'errorMessage.logFailed.markStepFailed'('from 1 h, system was not updated')
log.logInfo('from '+ diffInMinutes+ 'h, system was not updated')
}

FullCalendar V4 - How to account for shorter months in a recurring event series?

I'm using FullCalendar v4-alpha-3 with the RRule plugin to generate recurring events. It works as expected with only one problem: how do I modify a recurring event to account for months with fewer days than the starting month in a series?
For example, if the first monthly occurrence happens on January 29, 2019; the event will be repeated on the 29th of all subsequent months except in February since it only has 28 days (leap years excluded).
I've tried resetting dtstart to the first day of the following month. It works, except the event is no longer recursive.
Here's a stripped down snippet of my setup:
let calendar = new Calendar(calendarEl, {
plugins: [ rrulePlugin ],
events: [
{
rrule: 'DTSTART:20190129 RRULE:FREQ=MONTHLY;UNTIL=20200130;COUNT=13;BYMONTHDAY=29'
}
],
eventRender: function(info) {
...
// reset start date to the first day of the following month
// if current month has fewer days than base month
let start = event.start;
let day = start.getDate();
let now = new Date();
let currentMonth = now.getMonth();
let currentYear = now.getFullYear();
let daysInCurrent = getDaysInMonth(currentMonth + 1, currentYear);
let nextStart = start;
if (day > daysInCurrent) {
nextStart = new Date(currentYear, currentMonth + 1, 1);
event.setStart(nextStart);
event.setEnd(null);
}
}
});
I'd appreciate any insight.
Not quite the solution I hoped for, but RRule's bysetpos property seems to offer the next best alternative as it allows for a fallback date in case the one specified doesn't exist.
For example, the following would generate an occurrence on the 30th of every month; or the last day of the month if the 30th doesn’t exist:
FREQ=MONTHLY;BYMONTHDAY=28,29,30;BYSETPOS=-1.
Sourced from: https://icalevents.com/2555-paydays-last-working-days-and-why-bysetpos-is-useful/
I know this is an old question but maybe this will be usefull for someone:
I'm using momentjs library
monthly:
let endofmonth = moment('2020-02-29', "YYYY-MM-DD").endOf('month').format('DD');
let curday = moment('2020-02-29, "YYYY-MM-DD").format('DD');
single_event.title = title;
single_event.rrule = {};
single_event.rrule.freq = 'monthly';
single_event.rrule.dtstart = start_date;
single_event.rrule.interval = reminder_interval;
single_event.rrule.count = reminder_count;
if(endofmonth == curday){
// Checking if given day of the month is last
single_event.rrule.byweekday = ['mo','tu','we','th','fr','sa','su'];
single_event.rrule.bysetpos = -1;
}
else{
single_event.rrule.bymonthday = parseInt(curday);
}
calendar_events.push(single_event);
var calendar = new FullCalendar.Calendar(calendarEl, {
...
events: calendar_events
});
yearly:
single_event.title = title;
single_event.rrule = {};
single_event.rrule.dtstart = start_date;
single_event.rrule.count = parseInt(reminder_count);
if(endofmonth == curday){
// Checking if given day of the month is last
single_event.rrule.freq = 'monthly'; // Will work as yearly if interval is 12
single_event.rrule.interval = parseInt(reminder_interval)*12;
single_event.rrule.bymonthday = [28,29,30,31];
single_event.rrule.bysetpos = -1;
}
else{
single_event.rrule.freq = 'yearly';
single_event.rrule.bymonthday = parseInt(curday);
}
calendar_events.push(single_event);
var calendar = new FullCalendar.Calendar(calendarEl, {
...
events: calendar_events
});

Get Payment dates in a list

I have a payment check application, in that I get 2 strings:
String contractBegin = "01-01-2018";
String contractEnd = "31-12-2018";
Now every payment must be done the last Friday of the month. I need to calculate those dates and place it in a list or array.
Is there any optimal way to do that using the Java 8 nice features?
I started here:
String contractBegin = "01-01-2018";
String contractEnd = "31-12-2018";
LocalDate contractStart = LocalDate.parse(contractBegin, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
LocalDate contractStop = LocalDate.parse(contractEnd, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
System.out.println(contractStart);
System.out.println(contractStop);
List<LocalDate> payCheck= new ArrayList<>();
for (int i = 0; i < args.length; i++) {
payCheck.add(...) ??
}
I am not sure about your args array. But If you want to get every last friday of month between the contract start and end date. I would do as follow :
String contractBegin = "01-01-2018";
String contractEnd = "31-12-2018";
LocalDate contractStart = LocalDate.parse(contractBegin, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
LocalDate contractStop = LocalDate.parse(contractEnd, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
List<LocalDate> payCheck = new ArrayList<>();
LocalDate payCheckDate = contractStart;
while (payCheckDate.isBefore(contractStop)) {
payCheckDate = payCheckDate
.with(lastDayOfMonth())
.with(previousOrSame(DayOfWeek.FRIDAY));
payCheck.add(payCheckDate);
payCheckDate = payCheckDate.with(TemporalAdjusters.firstDayOfNextMonth());
}
payCheck.forEach(System.out::println);
This gives you every last friday of each month.
Another alternative to #gnostrenoff's answer is to use TemporalAdjusters.lastInMonth() method, which gives you the specified last day of week in the month:
// get the last Friday of the month
payCheckDate = payCheckDate.with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY));
The rest of the while loop is the same as #gnostrenoff's answer.

date time condition in razor view

How to set a condition to say if a data in a table is less than 5 days ago and then display a users information.
Below I can say less than date now.
#foreach (var item in Model)
{
if(item.RegisteredAt < DateTime.Now )
{
}
}
You can get the difference between two dates as a TimeSpan and use TotalDays property.
(DateTime.Now - item.RegisteredAt).TotalDays < 5
You can pass in a negative number to the AddDays function.
if(item.RegisteredAt < DateTime.Now.AddDays(-5)) {
If you wanted to ignore the time portion then you should compare them off the Date property.
if(item.RegisteredAt.Date < DateTime.Today.AddDays(-5)) {
if(item.RegisteredAt.Substract(DateTime.Now).Days.ToString().AsInt() < 5)
{
#* your expected code *#
}

How Do I get value from sql search based on the start and end dates?

I have a Personnel Roles Table where employees are assigned daily roles or roles with specific start and end dates.
Managers have asked for a sort of manpower plan table which lists an employee’s daily role and this how I generate the table
private string CreateHTMLTable(Int32 month)
{
StringBuilder strBuilder = new StringBuilder();
System.Data.DataTable dtAllStaff = new System.Data.DataTable();
//get all staff
PersonelApplication.Classes.PersonelClass PersonnelClass = new PersonelClass();
dtAllStaff = PersonnelClass.GetAllPersonel();
//create manpower data table
System.Data.DataTable dtManPowerDataTable = new System.Data.DataTable();
//create montlhy dt
//get number of days in month
int daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, month);
//get first day in month
DateTime firstDayInMonth = new DateTime(DateTime.Now.Year, month, 1);
//get last day in month
DateTime lastDayInMonth = new DateTime();
lastDayInMonth = firstDayInMonth.AddMonths(1).AddDays(-1);
//start table
strBuilder.Append("<table>");
//create header based on number of days in the month
//append tr strat
strBuilder.Append("<tr>");
//add name header for personnle
strBuilder.Append("<th>");
strBuilder.Append("Staff");
strBuilder.Append("</th>");
for (int i = 1; i <= lastDayInMonth.Day; i++)
{
strBuilder.Append("<th>");
strBuilder.Append(i.ToString() + "/" + month.ToString());
strBuilder.Append("</th>");
}
//append tr end to header row
strBuilder.Append("</tr>");
System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection();
sqlConn.ConnectionString = ConnectionClass.CreateConnection.getConnectionString();
using (sqlConn = ConnectionClass.CreateConnection.publicGetConn())
{
sqlConn.ConnectionString = ConnectionClass.CreateConnection.getConnectionString();
try
{
sqlConn.Open();
if (sqlConn.State == ConnectionState.Open)
{
foreach (DataRow row in dtAllStaff.Rows)
{
string personnelName = "";
string personnelCode = "";
Int32 personnelID = 0; ;
personnelCode = row[1].ToString();
strBuilder.Append("<tr>");
strBuilder.Append("<td>");
strBuilder.Append(personnelCode);
strBuilder.Append("</td>");
for (int i = 1; i <= lastDayInMonth.Day; i++)
{
//here get the each employee's planned role as well
//as actual role
}
strBuilder.Append("</tr>");
}
}
}
catch (Exception ex)
{
//pouplate later
}
finally
{
}
}
//end table
strBuilder.Append("</table>");
return strBuilder.ToString();
}
My issue is the SQL function which will return the employees role for a particular day.
--actual end date for this role is '08-18-2012'
declare #sdate date
set #sdate= '08-14-2012'
SELECT
CONVERT(date,startdate,101)
,CONVERT(date,EndDate,101)
,StartDate
,EndDate
,fk_PersonelID
,fk_RoleID
FROM [dbo].JobRolesTable
where #sdate between StartDate and EndDate
and fk_PersonelID = 40
But If I do a search for the next day which is the '08-15-2012’,I get nada
Bascially I want to return an employee’s role on any day of the month and ‘na’ if there’s none
I don’t want to use a cursor for this but is there another way I can achieve this
DECLARE #sdate DATE = '20120814';
SELECT
CONVERT(DATE,StartDate,101) -- what is the purpose of 101 here?
,CONVERT(DATE,EndDate,101) -- what is the purpose of 101 here?
,StartDate
,EndDate
,fk_PersonelID
,fk_RoleID
FROM [dbo].JobRolesTable
WHERE #sdate >= StartDate
AND #sdate < DATEADD(DAY, 1, EndDate)
AND fk_PersonelID = 40;
You are probably populating your parameters incorrectly.
If your query is of the form
SELECT *
FROM Table
WHERE (#SearchDate BETWEEN #StartDate AND #EndDate) AND Id=#Id
(which yours appears to be), then it will return the correct values from the db as long as the dates are being specified correctly.
Can you show the code where you're actually attempting to use the SqlConnection that you're opening in the posted code?