I'm trying to enable only Thursdays and Sundays but also disable some specific Sundays or Thursdays.
I'm trying with this function but it's not working yet:
<script>
var unavailableDates = ["2013-03-31", "2013-03-24"];
function disabledays(date) {
ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
if ($.inArray(ymd, unavailableDates) == 0) {
return [false, "", "Unavailable"]
} else {
//Show only sundays and thuersdays
var day = date.getDay();
return [(day == 0 || day == 4)];
}
$('#txtDate').datepicker({
beforeShowDay: disabledays
})
</script>
Two problems:
The code that builds a date string does not add a 0 to the month portion. You could change your unavailableDates array.
You need to check the return value of $.indexOf to see if it's >= 0 instead of just equal to zero.
With both changes:
var unavailableDates = ["2013-3-31", "2013-3-24"];
function disabledays(date) {
var ymd = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
if ($.inArray(ymd, unavailableDates) >= 0) {
return [false, "", "Unavailable"];
} else {
//Show only sundays and thuersdays
var day = date.getDay();
return [(day == 0 || day == 4)];
}
}
$('#txtDate').datepicker({
beforeShowDay: disabledays
});
Example: http://jsfiddle.net/XJKbV/
Related
I'm making a PWA on angular 8 / ionic 5. Users can create events and have them listed on a feed page. Problem is, that the date and the time of each event does not get displayed and gives the error "NaN" on iphones/iOS devices. Both date and time get their information from start_at which is the time in the format of "hh:mm:ss".
Following code shows how we receive the response data from our MySQL php laravel server for listing the events:
getTodos() {
console.log("arrived to gettodos");
var id = this.userInfo.id
this.todoService.getTodos('', '', '', id, false).subscribe(res => {
console.log("res", res);
console.log("frimes", res['frimes']);
// debugger;
// console.log(res);
if (res['code'] === 200) {
// console.log(res['data']);
const userFrimes: any[] = res['frimes'];
this.todos = [] as any[];
console.log(userFrimes);
if (userFrimes && userFrimes.length > 0) {
userFrimes.forEach(uf => {
var timeofFrime = this.formatAMPM(uf.start_at);
if (!this.todoService.isFrimeExpired(uf.start_at)) {
this.todos.push({
owner: this.userInfo.username,
title: uf.title,
message: uf.description,
date: uf.start_at,
time: timeofFrime,
max: uf.max,
guests: uf.member.length, //uf.guests == null ? 0 : uf.guests,
frime_id: uf.id,
status: uf.status,
user_id: uf.user_id
});
}
});
}
} else if (res['code'] === 205) {
} else if (res['code'] === 401) {
}
}, err => {
//this.errorMessage = err.message;
console.log(err);
});
}
here you can see that the properties date and time are being fetched for the formatAMPM() function and changed to the AM/PM date format.
formatAMPM(d) {
let dd = d + " UTC";
let date = new Date(dd);
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
var min = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + min + ' ' + ampm;
return strTime;
}
here the final date string gets displayed in the pipe fields where it shows the "NaN" error on ios.
the error itself says:
ERROR Error: InvalidPipeArgument: 'Unable to convert "2021-05-19 17:15:38" into a date' for pipe 'Re'.
what does 'Re' mean btw?
<ion-col size="3" class="date-wrapper">
<h3 class="notification-date">
{{ item.date | date: "shortDate" }}
</h3>
<h3 class="notification-date">
{{ item.time | date: "HH:mm" }}
</h3>
<h3 class="notification-date">{{ item.guests + '/' + item.max }}</h3>
</ion-col>
hope you can help me fixing this, because this is giving me soooo many headachse lately...
thanks in advance!
ok i have fixed it by adding this line of code:
d = d.replace(" ", "T");
the date came in a format like dd-MM-yyyy HH:mm:ss and i needed to add the "T" so it is like dd-MM-yyyyTHH:mm:ss
formatAMPM(d) {
d = d.replace(" ", "T");
let dd = d + " UTC";
let date = new Date(dd);
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
var min = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + min + ' ' + ampm;
return strTime;
}
After looking at many solutions, I got the following solutions that does exactly what I want.
SOLUTION 1 : works well except it does not work in IE(11)
I will much appreciate if someone can help me out fixing this for IE.
code taken from :https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement
function checkRows(oField, oKeyEvent) {
var nKey = (oKeyEvent || /* old IE */ window.event || /* check is not supported! */ { keyCode: 38 }).keyCode,
// put here the maximum number of characters per line:
nCols = 30,
// put here the maximum number of lines:
nRows = 5,
nSelS = oField.selectionStart, nSelE = oField.selectionEnd,
sVal = oField.value, nLen = sVal.length,
nBackward = nSelS >= nCols ? nSelS - nCols : 0,
nDeltaForw = sVal.substring(nBackward, nSelS).search(new RegExp("\\n(?!.{0," + String(nCols - 2) + "}\\n)")) + 1,
nRowStart = nBackward + nDeltaForw,
aReturns = (sVal.substring(0, nSelS) + sVal.substring(nSelE, sVal.length)).match(/\n/g),
nRowEnd = nSelE + nRowStart + nCols - nSelS,
sRow = sVal.substring(nRowStart, nSelS) + sVal.substring(nSelE, nRowEnd > nLen ? nLen : nRowEnd),
bKeepCols = nKey === 13 || nLen + 1 < nCols || /\n/.test(sRow) || ((nRowStart === 0 || nDeltaForw > 0 || nKey > 0) && (sRow.length < nCols || (nKey > 0 && (nLen === nRowEnd || sVal.charAt(nRowEnd) === "\n"))));
return (nKey !== 13 || (aReturns ? aReturns.length + 1 : 1) < nRows) && ((nKey > 32 && nKey < 41) || bKeepCols);
}
<form>
<p>Textarea with fixed number of characters per line:<br />
<textarea cols="50" rows="10" onkeypress="return checkRows(this, event);" onpaste="return false;" /></textarea></p>
</form>
SOLUTION 2
It works in IE but it fails in when editing the lines. You type a line, go back using left arrow keys and type you can type 1 letter and the cursor goes back to the end.
code taken from : http://cgodmer.com/?p=55 that
//limit # of lines of a text area and length of those lines
//<textarea rows="4" chars="40" onkeyup="limitTextareaLine(this, event)" ></textarea>
//Author: CGodmer (Feb 22, 2012)
function limitTextareaLine(x, e, nRows, nChars) {
var rows = $(x).val().split("\n").length; //number of rows
var lineCharLimit = nChars; //number of characters to limit each row to
var rowLimit = nRows; //number of rows to allow
//limit length of lines
for (var i = 0; i < rows; i++) {
var rowLength = $(x).val().split("\n")[i].length;
//check to see if any of the rows have a length greater than the limit
if (rowLength > lineCharLimit) {
//if it does save the beg index of the row
var rowstartindex = $(x).val().indexOf($(x).val().split("\n")[i]);
//use the index to get a new value w/ first lineCharLimit number of characters
var newval = $(x).val().substring(0, rowstartindex + lineCharLimit)
+ $(x).val().substring(rowstartindex + rowLength, $(x).val().length);
//replace that value in the textarea
$(x).val(newval);
//set character position back to end of the modified row
setCaretPosition($(x)[0], rowstartindex + lineCharLimit);
}
}
//limit # of lines to limit to is rows attribute
while($(x).val().split("\n").length > rowLimit) {
$(x).val($(x).val().substring(0, $(x).val().length - $(x).val().split("\n")[rowLimit].length - 1));
}
}
//Set caret position in the supplied control to position
//From: http://blog.vishalon.net/index.php/javascript-getting-and-setting-caret-position-in-textarea/
function setCaretPosition(ctrl, pos) {
if (ctrl.setSelectionRange) {
ctrl.focus();
ctrl.setSelectionRange(pos, pos);
}
else if (ctrl.createTextRange) {
var range = ctrl.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea rows="5" cols="10" onkeyup="limitTextareaLine(this, event, 5, 10)" ></textarea>
Try this one, it may solve this problem.
function ValidationAddress() {
var allText;
allText = document.getElementById("<%= txtAdd1.ClientID %>").value;
allText = document.getElementById('<%=txtAdd1.ClientID%>').value;
var A = allText.split('\n');
var L = A.length;
if (L > 3 && event.keyCode != 8 && event.keyCode != 46) {
alert("You have exceeded maximum limit.Cannot insert more than 3 lines.");
valert = false;
return false;
}
var arr = allText.split("\n");
for (var i = 0; i < arr.length; i++) {
if (arr[i].length > 10) {
alert("You have exceeded the Maximum Limit..Characters per line is 70 in Address Field !");
valert = false;
return false;
}
}
}
This ActionScript code I have been working on for a few days now works 100% just fine in JavaScript, but when I try to compile it in ActionScript it says I have unexpected /, ), and } symbols. Is this syntax wrong and if so how should I fix it? I figured I could test it as Javascript for quicker testing using http://jsfiddle.net/ but now I'm like =(
var txt = "This is a [rainbow]test to show that I can[/rainbow] make whatever I want [rainbow]appear as a rainbow[/rainbow] because I am [rainbow]awesome[/rainbow].";
if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
var colors = ['f0f', 'f0c', 'f09', 'f06', 'f03', 'f00', 'f30', 'f60', 'f90', 'fc0', 'ff0', 'cf0', '9f0', '6f0', '3f0', '0f0', '0f3', '0f6', '0f9', '0fc', '0ff', '0cf', '09f', '06f', '03f', '00f', '30f', '60f', '90f', 'c0f'];
function rainbowify(text) {
return text.replace(/\[rainbow\](.+?)\[\/rainbow\]/g, function(_, inner) {
return inner.replace(/./g, function(ch, i) {
return '<font color="#' + colors[i % colors.length] + '">' + ch + '</font>';
});
})
}
txt = rainbowify(txt);
document.write(txt);
}
Well, this is it:
txt = txt.replace("'", "#");
if ((txt.indexOf("[rainbow]") > -1) && (txt.indexOf("[/rainbow]") > -1)) {
var firstChar = txt.indexOf("[rainbow]") + 9;
var lastChar = txt.indexOf("[/rainbow]");
while (lastChar <= txt.lastIndexOf("[/rainbow]")) {
var RAINBOWTEXT = '';
var i = firstChar;
while (i < lastChar) {
RAINBOWTEXT += txt.charAt(i);
i++
}
var text = RAINBOWTEXT;
var texty = '';
colors = new Array('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000','ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00','99ff00','66ff00','33ff00','00ff00','00ff33','00ff66','00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff','0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff');
i = 0;
while (i <= text.length) {
var t = text.charAt(i);
if (t != undefined) {
texty += "<font color=\"#" + colors[i % colors.length] + "\">" + t + "</font>";
i++;
}
}
texty = texty.replace("> <", "> <");
var REPLACEME = "[rainbow]" + RAINBOWTEXT + "[/rainbow]";
txt = txt.replace(REPLACEME, texty);
if (lastChar == txt.lastIndexOf("[/rainbow]")) {
break;
}
nextChar = lastChar + 10;
firstChar = txt.indexOf("[rainbow]", lastChar) + 9;
lastChar = txt.indexOf("[/rainbow]", lastChar);
}
}
txt = txt.replace("#", "'");
My string format is: M/d/yyyy h:m:s aa
Now, I want to change it in yyyy-MM-ddTHH:mm:ss format.
How can I change it in this format. Please tell me appropriate solution
The method getConvertedDate(String), will do a plain text parsing for conversion.
private String getConvertedDate(String inputDate) {
// extract and adjust Month
int index = inputDate.indexOf('/');
String month = inputDate.substring(0, index);
if (month.length() < 2) {
month = "0" + month;
}
// extract and adjust Day
inputDate = inputDate.substring(index + 1);
index = inputDate.indexOf('/');
String day = inputDate.substring(0, index);
if (day.length() < 2) {
day = "0" + day;
}
// extract Year
inputDate = inputDate.substring(index + 1);
index = inputDate.indexOf(' ');
String year = inputDate.substring(0, index);
// extract Hour
inputDate = inputDate.substring(index + 1);
index = inputDate.indexOf(':');
String hour = inputDate.substring(0, index);
// extract and adjust Minute
inputDate = inputDate.substring(index + 1);
index = inputDate.indexOf(':');
String minute = inputDate.substring(0, index);
if (minute.length() < 2) {
minute = "0" + minute;
}
// extract and adjust Second
inputDate = inputDate.substring(index + 1);
index = inputDate.indexOf(' ');
String second = inputDate.substring(0, index);
if (second.length() < 2) {
second = "0" + second;
}
// extract AM/PM marker
// adjust hour, +12 for PM
inputDate = inputDate.substring(index + 1);
String am_pm_marker = inputDate.substring(0);
if (am_pm_marker.equalsIgnoreCase("pm")) {
int hourValue = 0;
try {
hourValue = Integer.parseInt(hour);
} catch (Exception e) {
}
hourValue += 12;
hour = "" + hourValue;
if (hour.length() < 2) {
hour = "0" + hour;
}
} else {
if (hour.length() < 2) {
hour = "0" + hour;
}
}
String outputDate = year + "-" + month + "-" + day;
outputDate += "T" + hour + ":" + minute + ":" + second;
return outputDate;
}
Sample input and output:
String input = "04/01/2012 9:55:47 pm";
System.out.println("Output: " + getConvertedDate(input));
// Output: 2012-04-01T21:55:47
Date date = (Date)new SimpleDateFormat("M/d/yyyy h:m:s aa").parse(your_string_date);
String finalFormat = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss").format(date)
Basically the first SimpleDateFormat recognizes your original format and parses it into a Date. Then the second one formats the date object to what you need.
I don't have jdk around to test here, but it should work.
Check this links for format syntax in case something doesn't work:
http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
How to create/read/delete cookie in blackberry widget?
have same issue but trying out these codes:
function createCookie(name, value, days) {
eraseCookie(name);
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}