i'm not sure if this is possible but i can't find any clue of doing this with multidatespicker..
i'm creating a web booking system which need to allow customer to select any booking date which they like.
But now my client was requesting to create package like weekly package(4 times per month), biweekly(1 times per 2 weeks) and etc..For weekly example.. when customer choose tuesday of that week.. the rest of 6 days all will be disable.. and for biweekly.. for that week and next week will be disable..
Thousand appreciate for someone who could help :)
I have the same issue: in my booking project the user must can select days range but also week range (only from Saturday to Saturday).
I managed the selection of the week on onSelect() event of multiDatesPicker() init function: by click on a day of the week MultiDatesPicker auto-select the relative week from Saturday to Saturday.
Unfortunately, for me the open issue is the hover event, because I want MultiDatesPicker also hover the week by pass hover the days of a week, not only select it, so the user could have perception to really choose weeks, not days.
It's singular that MultiDatesPicker has not a onHover() function to manage the "pre-selection"/hover event.
var autoselectRange = [0, days_range];
$('.multidatespicker-wrapper').multiDatesPicker({
numberOfMonths: [1, 2],
minDate: 1,
firstDay: 1,
mode: 'daysRange',
onSelect: function(dateText, inst) {
var selectedDate = $.datepicker.parseDate($.datepicker._defaults.dateFormat, dateText);
from_date = new Date(moment(dateText, "MM/DD/YYYY").format("YYYY-MM-DD"));
to_date = new Date (moment(dateText, "MM/DD/YYYY").add('days', days_range - 1).format("YYYY-MM-DD"));
if (weekRange) {
// Setting of Start and End of the week
if (from_date.getDay() == 6) numDaysToWeekStart = 0; // because Saturday in this case it is Start of the week
else numDaysToWeekStart = from_date.getDay() + 1;
from_date = new Date(from_date.setDate(from_date.getDate() - numDaysToWeekStart));
to_date = new Date(to_date.setDate(to_date.getDate() - numDaysToWeekStart));
// Setting of the days of the week
date = new Date(from_date);
weeks = [];
while (date <= to_date) {
weeks.push(new Date(date));
date.setDate(date.getDate() + 1);
}
// Selection of the days of the week/weeks in MDP Calendar
$(this).multiDatesPicker('resetDates', 'picked');
$(this).multiDatesPicker('addDates', weeks);
}
// Any more controls
},
autoselectRange: autoselectRange,
pickableRange: days_range,
// any more settings });
I hope It could be a help; if you have some idea to manage hover event and you can share it. Thanks
Related
I have a simple spreadsheet listing certificates and expiry dates. Before we moved this to sharepoint online we had a macro than on opening the spreadsheet would check dates in a range of cells and highlight those within three months. It was intended to highlight anything up for renewal before it expired.
I appreciate macros are not an option in Excel online. Can this (or something very similar) be achieved in Office Scripting?
It should be possible to create an Office Script that highlights cells with a date that is within three months of the present.
Something Like:
function main(workbook: ExcelScript.Workbook)
{
// highlight all days between today and the next number of days out
// Number of days to look ahead
const daysOut = 90;
// Excel by default stores dates as the number of days after January 1, 1900
const dayMin = currentDaysSince1900();
const dayMax = dayMin + daysOut;
// Need to target the column to look at and how far down the column
const columnToLookAt = "A";
const rowStart = 1;
const rowEnd = 4;
const rangeAddress = `${columnToLookAt}${rowStart}:${columnToLookAt}${rowEnd}`;
const sheet = workbook.getActiveWorksheet();
// get range column
const range = sheet.getRange("A1:A3");
const values = range.getValues();
// iterate through the rows of values
for (let i =0 ; i < values.length; i++) {
const value = values[i][0];
console.log(value);
if (typeof value === "number") {
// only look at numbers
if (value >= dayMin && value <=dayMax ) {
// highlight
const rangeAddress = `${columnToLookAt}${rowStart +i}`;
const range = sheet.getRange(rangeAddress);
range.getFormat().getFill().setColor("yellow");
}
}
}
}
/**
* Current Days since Jan 1 1900
* Equivalent to number of current excel day
*/
function currentDaysSince1900() {
// method returns the number of milliseconds elapsed since January 1, 1970
const nowMilliseconds = Date.now();
const millisecondsPerDay = 24 * 60 * 60 * 1000 ;
const nowDays = Math.floor(nowMilliseconds / millisecondsPerDay);
const daysBetween1900And1970 = 25567;
const elapsed = nowDays + daysBetween1900And1970 +2; // add two to include both jan 1s
return elapsed;
}
In terms of triggering the script:
Office Script does not currently support running a script on opening a workbook.
You can manually trigger the script whenever you like.
You can also create a Microsoft Power Automate flow to run the script every day to keep the workbook updated.
More Office Script resources:
Official Microsoft Office Script Date Example
Official Microsoft Office Script Examples
wandyezj office script examples
Please make sure you understand my problem before replying, it is not as simple as it looks. Please don't just do a google search and post the link to the results; I already looked.
I have a VB.Net application that we are replacing with a Java application. The purpose of the application is to write an excel sheet (.xls). The file is then sent over to a second party and they process the data in it. I am using the APACHE POI to write the file.
The final product is being rejected by the second party because two time fields are "not valid". After scratching my head for a while, I noticed that Java produced file and VB.Net produced file are handling 0 date values differently. Let's say the time is suppose to be 3:30 PM in military time, the data appears as 15:30 on both files. The problem is the date portion of the field:
VB.Net generated: 1/0/1900 15:30
Java generated: 1/1/1970 15:30
I can't seem to find a way to have the apache POI mimic the way excel handles 0 dates. The following are some of the things I tried.
I set my date/time variable in the java application as 1/0/1900 15:30. This gives me an error in the application.
I set my variable as a string and pass it to the worksheet and then set the format of the cell. I don't get an error, but the data stays as 'general' until I double click on the cell and press Enter. This process is suppose to be automated so this is not an option.
I set the formula of the cell to =TIMEVALUE("15:30"), but this was not accepted by the 2nd party.
Has anyone else ran into this problem? Can anyone think of a way around this? Having the second party change the way they read the file is not an option.
What you need to know is that Excel stores datetime values as floating point double values. There 0 = 00:00:00 and 1 = 24:00:00 = 01/01/1900 00:00:00. Also 0.5 = 12:00:00 and 1.5 = 36:00:00 = 01/01/1900 12:00:00. So in other words, Excels datetime values are starting with 0 and 1 is one day and is 01/01/1900. Also 1/24 is one hour, 1/24/60 is one minute and 1/24/60/60 is one second.
The problem using a Java Date is that the months in Calendar constructors are 0 based. So month 0 is January and new GregorianCalendar(1900, 0, 1, 15, 30, 0) will be 01/01/1900 15:30:00. And there is not a day 0, so new GregorianCalendar(1900, 0, 0, 15, 30, 0) will be 12/31/1899 15:30:00 and this will be -1 for Excel.
Because the problems with Excels date behavior are known, apache poi provides DateUtil.
Using this we can do:
import java.io.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.util.Calendar;
import java.util.GregorianCalendar;
class XSSFNullDateTest {
public static void main(String[] args) {
try {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
CreationHelper creationHelper = wb.getCreationHelper();
CellStyle cellStyleTime = wb.createCellStyle();
cellStyleTime.setDataFormat(creationHelper.createDataFormat().getFormat("hh:mm:ss"));
//using a Calendar:
Calendar calendar = new GregorianCalendar(1900, 0, 1, 15, 30, 0);
System.out.println(calendar.getTime()); //01/01/1900 15:30:00
double doubleTime = DateUtil.getExcelDate(calendar, false);
System.out.println(doubleTime); //1.6458333333333335
Cell cell = sheet.createRow(0).createCell(0);
cell.setCellValue(doubleTime-1); //subtract 1 so we have day 0
cell = sheet.getRow(0).createCell(1);
cell.setCellValue(doubleTime-1); //subtract 1 so we have day 0
cell.setCellStyle(cellStyleTime);
//using a string:
doubleTime = DateUtil.convertTime("15:30:00");
System.out.println(doubleTime); //0.6458333333333334 = day 0 already
cell = sheet.createRow(1).createCell(0);
cell.setCellValue(doubleTime);
cell = sheet.getRow(1).createCell(1);
cell.setCellValue(doubleTime);
cell.setCellStyle(cellStyleTime);
OutputStream out = new FileOutputStream("XSSFNullDateTest.xlsx");
wb.write(out);
wb.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
All,
I've been looking all day and have tried numerous solutions, but just can't get it to work. Our team projects a list that is constantly updated and we want to highlight only newly created items for 5 minutes. After 5 minutes, the row would return to normal. (FYI- the list is projected on a display and updated using AJAX asynchronous update every 15 seconds)
Basically, I want to set conditional formatting on list items created in the last 5 minutes. If the item was created in the last 5 minutes, the row will be highlighted. After the 5 minutes are up, the row would return to normal.
I tried SharePoint Designer conditional formatting by creating a calculated column in Date/Time format called "Created + 5" and tried to set an expression where the formatting is applied (row is highlighted) when "Created + 5" is greater than or equal to current date. So after 5 minutes, the row will no longer be highlighted (because the current date/time will exceed the "Created + 5" value)
Here is the expression from the SPD Advanced Condition Builder:
ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($thisNode/#Created_x0020__x002b__x0020_5_x))) >=
ddwrt:DateTimeTick(ddwrt:GenDisplayName(string($Today)))
I think the problem is that the [Current Date] option ($Today in the expression builder) only accounts for date and not time. It looks like it just ends up highlighting everything that was created today, which is not very useful.
Any thoughts or help!? I have never messed with the advanced conditions because usually the basic stuff works fine for me! If anyone has any other ideas too like JavaScript or anything else that would work, I am open to that too as long as it will continuously update!
Thanks all!!!!
[Today] actually doesn't work properly in 2010, there are some workarounds though, e.g. https://abstractspaces.wordpress.com/2008/05/19/use-today-and-me-in-calculated-column/.
You can also use the approach with calculated column: https://blog.splibrarian.com/2012/06/06/using-calculated-columns-to-add-color-coding-to-your-sharepoint-lists/
Since you want this to update automatically without requiring someone to manually refresh the page, JavaScript is your best bet. You can have a function run repeatedly on a specified interval, checking the current date against the values in a date column.
Something like the following code would work, though you may need to tweak the CSS selectors specified in the calls to document.querySelector and querySelectorAll to match your particular HTML.
<script>
formatCell();
function formatCell(){
var frequencyToCheck = 2 /* num seconds between updates */
var minutes = 5; /* num minutes back to highlight */
var targetColumn = "Display name of the column you want to check";
var formatting = "background-color:darkred;color:red;font-weight:bold;";
var comparisonDate = new Date();
comparisonDate.setHours(comparisonDate.getHours() - minutes);
var tables = document.querySelectorAll("table.ms-listviewtable"); /* should get all list view web parts on the page */
var t_i = 0;
while(t_i < tables.length){
var headings = tables[t_i].rows[0].cells;
var columnIndex = null;
var h_i = 0;
while(h_i < headings.length){
var heading = headings[h_i].querySelector("div:first-child");
if(heading != null){
var displayName = heading.DisplayName ? heading.DisplayName : (heading.innerText ? heading.innerText : heading.textContent);
displayName = displayName.replace(/^\s+|\s+$/g,''); /* removes leading and trailing whitespace */
if(displayName === targetColumn){
columnIndex = h_i;
break;
}
}
h_i += 1;
}
if(columnIndex != null){ /* we found a matching heading */
var rows = tables[t_i].rows;
for(var i = (rows.length > 0 ? 1 : 0); i < rows.length; i++){
var cells = rows[i].children;
if(cells.length <= columnIndex){continue;}
var valueToEval = cells[columnIndex].innerText ? cells[columnIndex].innerText : cells[columnIndex].textContent;
if(typeof valueToEval == "undefined"){valueToEval = "";}
valueToEval = new Date(valueToEval);
if(valueToEval > comparisonDate){
cells[columnIndex].setAttribute("style",formatting);
}else{
cells[columnIndex].setAttribute("style","");
}
}
}
t_i +=1;
}
setTimeout(formatCell,frequencyToCheck * 1000);
}
</script>
One potential pitfall is that while this approach will "age" records appropriately based on their displayed values (causing them to stop being highlighted as they grow stale), it won't automatically pick up new changes to the list; you'd need to refresh the page (or at least refresh the view in the web part) whenever you want to see updated information.
I think the title says it all.
I would like to run a job that e.g. Starts at Jun 19 2014 (say at 7 AM), ends at December 25 2015 (say at 11 PM) and runs every 9 days in between these two dates. I can set it up to work without an end date. But I don't know how to include all of it in one expression.
Update:
Does adding an EndAt() to my TriggerBuilder work?
mytrigger = (ICronTrigger)TriggerBuilder.Create()
.WithIdentity(triggerName, triggerGroup)
.WithCronSchedule(cron)
.EndAt(xxxx)
.Build();
You're in the right direction, schedules that need a lot of research to be generated with a cron expression can be easily generated via the API. For example, the trigger you want is the following:
var startDate = new DateTime(2014, 06, 19, 7, 0, 0);
var endDate = new DateTime(2015, 12, 25, 23, 0, 0);
var cronExpression = "0 0 12 1/9 * ? *"; //every nine days
ITrigger trig = TriggerBuilder.Create()
.StartAt(startDate)
.WithCronSchedule(cronExpression)
.WithDescription("description")
.WithIdentity(triggerKey)
.WithPriority(1)
.EndAt(endDate)
.Build();
If you want to see the cron expression generated:
ICronTrigger trigger = (ICronTrigger)trig;
string cronExpression = trigger.CronExpressionString;
I want to get the last weekday of a given month.
I've come across this simple answer on how to get the 1st/2nd/... weekday which works well.
The question is: How to get the last weekday of a given month?
Not every month has only 4 Sundays, so do I have to count the number of Sundays of the month, or is there a more elegant way to do this?
Had the same need recently, and the best I could come up with is the following, which is meant to be run every day to check if the current day is the last weekday of the current month:
<?php
$d = new DateObject('first day of this month', date_default_timezone());
$d->modify("+15 days");
$d->modify("first day of next month -1 weekday");
$last = date_format($d, 'd');
$today = new DateObject('today', date_default_timezone());
$today = date_format($today, 'd');
if ($today == $last) {
//bingo
}
?>
I have been testing and so far couldn't find an example where this fails. The reason for doing the modify("+15 days") in the middle is to be sure we are calling "next month" with a starting date that is not in the edge between two months, case where I believe this could fail.
Leaving the code shown before apparently covers all cases.
I finally came up with the following solution. I'm using NSDate-Extensions for convenience. dayOfWeek stands for Sunday (1) till Saturday (7) in the Gregorian calendar:
- (NSDate *)dateOfLastDayOfWeek:(NSInteger)dayOfWeek afterDate:(NSDate *)date
{
// Determine the date one month after the given date
date = [date dateByAddingMonths:1];
// Set the first day of this month
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.year = date.year;
dateComponents.month = date.month;
dateComponents.day = 1;
// Get the date and then the weekday of this first day of the month
NSDate *tempDate = [[NSCalendar currentCalendar] dateFromComponents:dateComponents];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *firstDayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:tempDate];
NSInteger weekday = firstDayComponents.weekday;
// Determine how many days we have to go back to the desired weekday
NSInteger daysBeforeThe1stOfNextMonth = (weekday + 7) - dayOfWeek;
if (daysBeforeThe1stOfNextMonth > 7)
{
daysBeforeThe1stOfNextMonth -= 7;
}
NSDate *dateOfLastDayOfWeek = [tempDate dateBySubtractingDays:daysBeforeThe1stOfNextMonth];
return dateOfLastDayOfWeek;
}