jQuery UI DatePicker - Disable all days except last day of month - jquery-ui

I'm trying to use the jquery UI datepicker to show a calendar with only the last day of the month selectable.
I've successfully used the beforeShowDay event to disable days of the week but not sure how I'd use this to disable everything but the last day of the month.

beforeShowDay is called for every date shown on the calender. When beforeShowDay is called, you need to determine if the date passed to it is the last day of the month.
The following JScript will return the last day of the month for a given year and month.
function LastDayOfMonth(Year, Month)
{
return(new Date((new Date(Year, Month+1,1))-1)).getDate();
}
Use the following code to determine if the beforeShowDay's date is the last of the month:
$('.selector').datepicker({
beforeShowDay: function (date) {
//getDate() returns the day (0-31)
if (date.getDate() == LastDayOfMonth(date.getFullYear(),date.getMonth())) {
return [true, ''];
}
return [false, ''];
}
});

function LastDayOfMonth(Year, Month) {
//set next month first day
//substract one day from it.
return new Date(new Date(Year, Month+1,1)-1).getDate();
}
This will work

Related

How to update the dynamic island view after a certain interval of time in App kill state.?

I want to start the dynamic island live activity for count down timer with event title.
Like christmas in 05 days.
I am trying to update it with the help of timer in extension, but not able to update the view.
Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [self] time in
if minute < 1 {
updateActivity(dynamicIslandType: dynamicIslandType, minute: 0)
time.invalidate()
}
I have tried this code in widget extension to update the view, but not able to get any update of the view.

Can you create a "seconds" timer in Google Sheets?

Test Timer Spreadsheet
My understanding is that it isn't possible due to the limitations of Spreadsheet Settings > Calculations. I have successfully implemented Days, Hours, and Minutes into my timer - but it would be cool to have the Seconds as well.
Formulae:
=IFERROR(DAY(AH9-NOW()),0)
=IFERROR(HOUR(AH9-NOW()),0)
=IFERROR(MINUTE(AH9-NOW()),0)
*AH9 refers to the grey date cell in the timer
The Seconds timer isn't essential, more aesthetic - but I was interested to see if it was possible or not.
I have added some script into your workbook which does run a seconds timer.
The script that I have added is subject to the limitations of Apps Script run time but I have added various triggers in which should hopefully fire up the script once it has ended. I have also added a button to start the script as well but you may want to delete this out?
The script on its own will run for 4-5 mins, the triggers should set this so that there is only a small interval when the seconds won't be working.
Please note that to make this script run it needs to add a date into a cell - if you set A1 to colour black, you will see this there. The script will add this in if you delete it out so no real need to worry about leaving it there etc.
If you need to change the cell where this is, just change the global variable in the apps script project.
Hope this helps!!
The script I used was as below. The triggers that I used were a time driven trigger based on a minute timer then set it to every minute. As each function of the script works for 15 seconds, this creates a loop for a minute, which is triggered every minute.
I did play around but unfortunately I couldn't get the maths right to make it run for any longer :)...
var CELL_RANGE = 'A1'
function updateCell() {
for (i=0; i<15; i++){
Utilities.sleep(1000);
var date = new Date();
SpreadsheetApp.getActiveSheet().getRange(CELL_RANGE).setValue(date);
SpreadsheetApp.flush();
updateCell1()
}
}
function updateCell1() {
for (i=0; i<15; i++){
Utilities.sleep(1000);
var date = new Date();
SpreadsheetApp.getActiveSheet().getRange(CELL_RANGE).setValue(date);
SpreadsheetApp.flush();
updateCell2()
}
}
function updateCell2() {
for (i=0; i<15; i++){
Utilities.sleep(1000);
var date = new Date();
SpreadsheetApp.getActiveSheet().getRange(CELL_RANGE).setValue(date);
SpreadsheetApp.flush();
updateCell3()
}
}
function updateCell3() {
for (i=0; i<15; i++){
Utilities.sleep(1000);
var date = new Date();
SpreadsheetApp.getActiveSheet().getRange(CELL_RANGE).setValue(date);
SpreadsheetApp.flush();
updateCell()
}
}

Do not allow past date for drop in fullcalendar

Hi I am using fullcalendar for schdule event
Now I want to disable pas date for drop event, So I fixed using following solution
$('#calendar').fullCalendar({
eventConstraint: {
start: moment().format('YYYY-MM-DD'),
end: '2100-01-01'
},
});
It working fine, but now I want to disable few days from week too, so I added dow in eventConstraint, now its stop working
$('#calendar').fullCalendar({
eventConstraint: {
start: moment().format('YYYY-MM-DD'),
end: '2100-01-01',
dow: [ 3, 5 ]
},
});
In short I want to disable past date and allow to select only wed and fri from calendar.
Is there anyway to fix issue.
Having given this some more thought after your comments, I think this is best solved using some custom code, via the eventDrop callback:
eventDrop: function(event, delta, revertFunc) {
var day = event.start.clone();
day.startOf("day");
var dayOfWeek = day.isoWeekday();
if (day.isBefore(moment().startOf("day")) || (dayOfWeek != 3 && dayOfWeek != 5)) {
revertFunc()
}
}
This will check for both of your constraints: if the day is in the past, or that the day is not a Wednesday and not a Friday, then revertFunc() is executed, which is a fullCalendar-provided callback which sends the event back to its original location on the calendar.
Here you can find a working demo: http://jsfiddle.net/ughug9xx/2/

How to detect month/year change

I am using the UIApplicationSignificantTimeChangeNotification to detect when the day changes:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "dayChanged:", name: UIApplicationSignificantTimeChangeNotification, object: nil)
#objc func dayChanged(notification: NSNotification){
}
Inside the dayChanged handler I want to test if the new day is the first day of a new month or first day of the new year.
I should test if NSCalendar.currentCalendar().components(NSCalendarUnit.Day, fromDate: NSDate()).day is equal to 1, but how to differentiate between month and year ?
Just check if month is first - then you have new year, if not then you have new month.

Data Grouping - Monthly (end-of-month)

I'm having a very difficult time trying to get my data to be grouped via month. I've even gone so far as to programmatically filter through my data to return only the last day of the month and calculate the monthly value. I've tried to find a good explanation on the 'dataGrouping' property but have had no luck understanding it nor properly implementing it. Every results returns my series in a daily interval.
My questions are as follows:
Is there a minimum number of data points needed for data grouping to
work?
Under the dataGrouping.units I've tried to use this
documentation but nothing has worked for me - Still results in a
daily interval - Could someone explain this for me?
Any help on this would be GREATLY appreciated.
Are you using HighStock graph?
If yes...
Sure, it takes a lot of data to get grouping. If datagrouping option is enabled, Highstock handle automatically the switch between every grouping mode. So if you don't have a lot of data, it will not work with default settings
So, if you want to group by default, you need to force the grouping.
series:[{
[...]
dataGrouping: {
approximation: "sum",
enabled: true,
forced: true,
units: [['month',[1]]]
}
}]
EDIT
Here is a working example demo (fork of a basic highstock demo)
http://jsfiddle.net/NcNvu/
Hope it helps!
Regards
We tried a Hack around this, where we used Highstock's (Splinechart) RangeSelector, Event and DataGrouping. On click of weekly rangeselectorButton we catch this event through setExtremes. Post catching the event approximate it to "sum". If you are using two series than iterate the object. Currently doing it weekly just extend it for Monthly using corresponding UNIT
events: {
setExtremes: function (e) {
if (e.rangeSelectorButton != undefined) {
var triger = e.rangeSelectorButton;
if (triger.type == 'week') {
$.each(this.series, function (index, obj) {
obj.options.dataGrouping.units[0] = ['week', [1]];
});
} else if (triger.type == 'day') {
$.each(this.series, function (index, obj) {
obj.options.dataGrouping.units[0] = ['day', [1]];
});
}
}
}
},

Resources