Tried 7 times to find a valid date - eonasdan-datetimepicker

I'm trying to invoke a calendar with every day blocked excepting Thursdays.
Some Thursdays will be blocked, so I use daysOfWeekDisabled and disableDate.
jQuery('.custom-calendar-2').datetimepicker({
format: "dd/mm/yyyy",
daysOfWeekDisabled: [0,1,2,3,5,6],
useCurrent: true,
inline: true,
/*beforeShowMonth: function (date) {
if (date.getMonth() == 8) {
return false;
}
},*/
defaultDate: null,
minDate: moment().add(1, 'days'),
disabledDates: [
moment('04/07/2016', 'MM/DD/YYYY'),
moment('04/21/2016', 'MM/DD/YYYY')
],
//toggleActive: true
});
If I comment the line
moment('04/07/2016', 'MM/DD/YYYY'),
my calendar works. I'm trying to debug this but I just don't get it. The console says:
Tried 7 times to find a valid date
How I can solve that error?
EDIT:
I've digged into the library. On line 1648 there is this snippet:
if (tries === 7) {
throw 'Tried 7 times to find a valid date';
}
Changing the number of tries to something bigger like 14 just does the work. I get the idea of avoid some kind of infinite loop, but this way you can't do a basic operation like blocking the current week.
I wonder if there is another better way that modifying the library myself/monkey patching. Or this should be directly patched into the repository?

You could use keepinvalid = true, when you try to set disabled days from the calendar.
https://eonasdan.github.io/bootstrap-datetimepicker/Options/#keepinvalid

I've sent a pull request for a temporal fix. https://github.com/Eonasdan/bootstrap-datetimepicker/pull/1558

Related

Odoo 12: How to disable past dates with datepicker?

How can I use datepicker in a Date field?
I try to disable past dates like that:
<field class="delivery_date" name="delivery_date" options="{'datepicker':{'minDate': 0}}"/>
But past dates are shown nevertheless.
It seems as if the options-tag is not parsed at all. I used the debugger to get an overview what happens in addons/web/static/src/js/fields/basic_fields.js (where datepicker is initialized) but there are no options declared.
Thanks in advance!
UPDATE:
That's my field definition
delivery_date = fields.Date(string='Delivery Date', help="Date on which sales order is delivered.", default=_get_default_delivery_date)
The default-method sets the date to the day after tomorrow.
My view declaration is above. That's all I have.
I expected that the datepicker is invoked as soon as I use it in "options"-attribute.
When I enter my website the datepicker is shown, when I click on that date-field, but the past dates are not disabled..
I tried multiple modules, but nothing works for me in js Odoo 14
#api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
doc = etree.XML(res['arch'])
for node in doc.xpath("//field[#name='date_invoice']"):
node.set('options', "{'datepicker': {'minDate': '%sT23:59:59'}}" % fields.Date.today().strftime(DEFAULT_SERVER_DATE_FORMAT))
res['arch'] = etree.tostring(doc)
return res
Try this, This may help you

How do I transpile an *expression* with babel?

Given the following:
require('babel-core').transform('3').code
Is there a way to get this to return 3 (an expression) instead of 3; (a statement)?
I've tried:
Searching the web and various sites for 'babel expression', 'babel transpile expression', and the like.
Passing (3), but that also was transformed into 3;.
Poking the babel internals to figure out what's going on, but I don't know enough about how it works to sort this out.
Passing the option minified: true, which claims to remove the trailing semicolon but doesn't actually seem to do anything.
Right now I'm using .replace(/;$/, ''), which works but seems absurd and error-prone.
#loganfsmyth provided the missing link on BabelJS.slack -- parserOpts.allowReturnOutsideFunction. Here's the code I came up with:
const babel = require('babel-core');
let script = 'return ((selector, callback) => Array.prototype.map.call(document.querySelectorAll(selector), callback))("#main table a.companylist",a => a.innerText)';
let transform = babel.transform(script, {
ast: false,
code: true,
comments: false,
compact: true,
minified: true,
presets: [
['env', {
targets: {
browsers: ['> 1%', 'last 2 Firefox versions', 'last 2 Chrome versions', 'last 2 Edge versions', 'last 2 Safari versions', 'Firefox ESR', 'IE >= 8'],
}
}]
],
parserOpts: {
allowReturnOutsideFunction: true,
}
});
let code = `return function(){${transform.code}}()`;
Output:
return function(){"use strict";return function(selector,callback){return Array.prototype.map.call(document.querySelectorAll(selector),callback)}("#main table a.companylist",function(a){return a.innerText});}()
My input script looks a bit funny just because of how I generated it, but you can see that it transformed those arrow expressions into regular functions and the whole thing is still an expression.
N.B. you may want to modify that last line to something like
let code = `(function(){${transform.code}})()`;
depending on your needs. I needed mine to be returned.

Utilities.formatDate() in Google Apps Script outputs previous date (e.g. input 25.05.2015 -> output 24.05.2015)

I have a problem with Google Docs' Utilities.formatDate() function.
I have a spreadsheet that contains all of the orders we place in the lab. When an order is delivered our lab manager enters the delivery date in the relevant cell in such a spreadsheet, in the following format: dd.MM.yyyy.
I created a script that, provided certain conditions, will email whoever placed that order alerting them that the order has been delivered on that particular date. Here is the code:
function DeliveryAlerts() {
try {
var email_dict = {"Y":"Y#Z.com"}
var spreadsheet = SpreadsheetApp.openById("ABC");
SpreadsheetApp.setActiveSpreadsheet(spreadsheet);
var sheet = spreadsheet.getSheetByName("Orders");
var values = sheet.getRange("A2:Q251").getValues();
var bgcolours = sheet.getRange("A2:Q251").getBackgrounds();
for(var i=0;i<=249;i++)
{
var j = i + 2;
if (values[i][16]=="Yes" && values[i][11]!="" && bgcolours[i][16]!="#b8b8b8")
{
var email_address = email_dict[values[i][13]];
var cur_date = Utilities.formatDate(values[i][11], "GMT+1", "EEE dd.MM.yyyy");
var message = "Hello there,\n\nYour order of " + values[i][4] + " has been delivered on "+ cur_date +".\n\nBest wishes";
var subject = "Delivery alert";
MailApp.sendEmail(email_address, subject, message,{replyTo:"abc#abc.com", name:"ABC"});
sheet.getRange("Q"+j).setBackground("#b8b8b8");
}
}
} catch (err) {
MailApp.sendEmail("abc#abc.com", "Delivery Alerts Script in Order Master List", err);
}
}
I use
Utilities.formatDate(values[i][11], "GMT+1", "EEE dd.MM.yyyy") to reformat the date from, say, 25.05.2015 (that is, the value in the cell) to Mon 25.05.2015. However, what I get instead is Sun 24.05.2015.
Does anybody know what is going on?
Thank you in advance.
Nicola
Check the time zone setting in the script editor. Under the FILE menu, choose PROJECT PROPERTIES in the script editor. It's possible to have a different time zone setting in Apps Script, than is in the spreadsheet. This is a common issue that arises. Apps Script allows a separate time zone setting from the spreadsheet. Also, even if the time is only off by one minute, if the time setting of the date is all zeros, it's common to get the problem that you are having. When a user enters a date, it's possible that no time setting is made. So the time is set to all zeros. The date is correct, but the time is all zeros. Even if the date was typed in at 3 in the afternoon, for example, and the date is correct, the time setting can be midnight of that day. So, even if you subtracted one second from that date, it would now be the day before.

setMinDate(...) for DatePicker doesn't work when invoked a second time

I'm in a particular situation in which I have to alter the min and max date of DatePicker according to the selected element of a Spinner. Here's the chunk of code I'm using to switch min and max date.
private void switchCalculationMethod(int method) {
calculationMethod = method;
switch (method) {
case METHOD_1:
datePicker.setMinDate(new LocalDate().minusWeeks(42).getMillis());
datePicker.setMaxDate(new LocalDate().plusDays(1).getMillis() - 1);
break;
case METHOD_2:
datePicker.setMinDate(new LocalDate().minusWeeks(2).getMillis()); // This don't work!!
datePicker.setMaxDate(new LocalDate().plusWeeks(40).getMillis()); // This works!!!
break;
}
datePicker.init(today.getYear(), today.getMonthOfYear() - 1,
today.getDayOfMonth(), this);
}
So, the DatePicker would get set up correctly the first time, problem occurs when I attempt to change the min date again (changing max date works). It would remain at the value I had set first. I'm thinking this is a bug. Am I doing something wrong here? Is there a workaround for this?.
PS : I'm using Joda time api.
This happens because method setMinDate() has check
if (mTempDate.get(Calendar.YEAR) == mMinDate.get(Calendar.YEAR)
&& mTempDate.get(Calendar.DAY_OF_YEAR) != mMinDate.get(Calendar.DAY_OF_YEAR){
return;
}
Simple workaround is to set min date with different year at first, for example
mPicker.setMinDate(0);
mPicker.setMinDate(new LocalDate().minusWeeks(2)
.toDateTimeAtStartOfDay().getMillis());
It works for me.
As said above, you can bypass the check by calling those before actually changing the value:
setMinDate(0);
setMaxDate(Long.MAX_VALUE);
If you want to reset the minimum or maximum value to its default, you can use the following values:
setMinDate(-2208902400000L); // Jan 1, 1900
setMaxDate(4102531200000L); // Jan 1, 2100
mPicker.setMinDate(0);
doesn't work for me.
Try to reinitialize the picker.
mPicker = new DatePickerDialog(..)
first update setMinDate to 0 after then setMinDate according to you dateobject
mPicker.setMinDate(0);
mPicker.setMinDate(datepickerObject.getTimeInMillis());

Validating two dates in acrobat javascripts

well the code I posted below all works perfectly except for a small detail. When I input today date in the field dateEntered, the later rejects it, it validates if the date entered is before todays date, validate if the date falls on a weekends, but it also show an error message when it is todays date. Actually the user should be able to enter Today or after date.
Anyone can tell me where am wrong, already tried every possible ways but still not working even the ( ==) or (===) or (<=) ..nothing
if (event.value!="")
{
var e = util.scand("ddd, dd.mmm.yy", event.value);
var a = (e.getTime()) < (new Date().getTime());
if (a) {
app.alert("The Date cannot be before Today's Date", 1);
event.rc = null;
}
if (e.getDay()==6 || e.getDay()==0) {
app.alert("Cannot take permission on a Weekend!", 2);
event.rc=null;
}
}
I found the solution to my problem, I had to set the hour to 0. Thank to the one who updated this on stackoverflow and sorry forget to retain your name.
if (event.value!="")
{
var e = util.scand("ddd, dd.mmm.yy", event.value);
var b=new Date();
b.setHours(0,0,0,0);
if (e<b) {
app.alert("ERROR: Date cannot be before"+" "+ new Date(b), 5);
event.rc = null;
}
if (e.getDay()==6 || e.getDay()==0) {
app.alert("ALERT: The date you entered ("+event.value+") falls on a WEEKEND!", 3);
event.rc=null;
}
}
This codes also contains a condition of removing one weekend from the dates since the number of leaves allowed to take ranges from 1 to 7 thus only one weekend is remove.