It's my first time working with ICS files and I'm having trouble getting it to work:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//test.com//NONSGML v1.0//EN
BEGIN:VEVENT
UID:test#test.com
ATTENDEE;CN=My Self ;RSVP=FALSE
DTSTAMP:TZID=Australia/Sydney:19700101T100000
DTSTART:19700101T100000
DTEND:19700101T100000
LOCATION:Online
SUMMARY:Test Title 10.0
DESCRIPTION:-
END:VEVENT
END:VCALENDAR
Not sure if this matters but this is how I've formatted it in Javascript:
var icsFile = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//test.com//NONSGML v1.0//EN\nBEGIN:VEVENT \nUID:test#test.com\nATTENDEE;CN=My Self ;RSVP=FALSE\nDTSTAMP:"+ dtstamp +"\nDTSTART:" + start + " \nDTEND:" + start + "\nLOCATION:" + location + "\nSUMMARY:" + summary + "\nDESCRIPTION:" + description + "\nEND:VEVENT\nEND:VCALENDAR";
When I run it in the ics validator: https://icalendar.org/validator.html
I get:
Error
Invalid DTSTAMP value, must be a valid date-time value near line # 4
Reference: 3.3.5. Date-Time
Question 1
When I check DTSTAMP, it's correct based on Form#3 : https://icalendar.org/iCalendar-RFC-5545/3-3-5-date-time.html
Question 2
How do I go about adding 3 hours into the DTEND timestamp in Javascript?
Thanks!
To fix the validation error, you need a semicolon after DTSTAMP instead of a colon:
DTSTAMP;TZID=Australia/Sydney:19700101T100000
Related
I'm new to javascript so I apologize if this is a very basic question.
I am building (Drag & drop) forms for user input of data through a website. I have two time inputs (STARTTIME and TESTTIME) that are in HH:MM format. I need to display the time 15 minutes after STARTTIME (15MIN) and the number of minutes that have passed between STARTTIME AND TESTTIME (TIMEDIF).
The website provides the drag & drop form editor and has a field where I can add javascript to the form.
I've figured out how to take string inputs of "HH:MM" and output the values I need.
I am struggling with extracting the input from the two time fields (STARTTIME and TESTTIME) and writing to the 15MIN and TIMEDIF fields.
For returning the input from the form, I've tried using:
var atime = $("#" + STARTTIME + "input");
var ttime = $("#"+ TESTTIME + "input");
//-or-
var atime = $("div[id=STARTTIME] input");
var ttime = $("div[id=TESTTIME] input");
//and for setting the 15MIN and TIMEDIF variables
$("div[id=15MIN] input").val(tqtime);
$("div[id=TIMEDIF] input").val(difftime);
//tqtime and difftime are in "HH:MM" and number format, respectively and are calculated from atime and ttime.
I have tested the output of the code from atime and ttime defined as "HH:MM" strings to tqtime and difftime, which has been successful.
However, all variables are undefined when used with the form, leading me to believe that I'm not returning the input correctly.
When you call $("someselector"), what you get is a jQuery element. This is more than just the value of the input, and thus you must actually call a function to get that value. With jQuery, you use the .val() method to achieve this. Assume that "#" + STARTTIME + input" and "#" + TESTTIME + "input" are ids of input elements, getting the values would look like this:
var atime = $("#" + STARTTIME + "input").val();
var ttime = $("#" + TESTTIME + "input").val();
I am trying to load a javascript in WebView to do some calculations and get the output in a string. I tried to use following code
string htmlFragment = "<html><head><script type='text/javascript'>" +
"function doubleIt(incoming){ " +
" var intIncoming = parseInt(incoming, 10);" +
" var doubled = intIncoming * 2;" +
" document.body.style.fontSize= doubled.toString() + 'px';" +
" return doubled.toString());" +
"};" +
"</script></head><body>" +
"<div id = 'myDiv'>I AM CONTENT</div></body></html>";
htmlView.NavigateToString(htmlFragment);
htmlView.LoadCompleted += async(s1,e1) =>
{
string result = await htmlView.InvokeScriptAsync("eval", new string[] { "doubleIt(25)" });
Debug.WriteLine(result);
};
Update
I am able to load simple javascript easily now based on help provided in the answer. But now I am facing issues when there is more than one function in javascript, I am getting an exception. I am trying the following code
string htmlFragment = #"<html><head><script type='text/javascript'>" +
"function a(){return 10;};" +
"function b(){return 20;};" +
"function c(){return 30;};" +
"return (a()*b()*c());" +
"</script></head><body>" +
"<div id = 'myDiv'>I AM CONTENT</div></body></html>";
Please suggest.
The documentation for this feature is really poor. It took me some time to figure out how to invoke Javascript in UWP WebView
When you first look at the function call webView.InvokeScriptAsync(string,string[]) your initial reaction is that they want the function name as the first parameter and then the function paramaeters as the string array. (mainly because the MSDN documentation says this)
Parameters
scriptName
Type: System.String [.NET] | Platform::String [C++]
The name of the script function to invoke.
arguments
Type: System.String[]
[.NET] | Platform::Array [C++]
A string array that
packages arguments to the script function.
HOWEVER, this is wrong and will lead to hours of head banging. REALLY, what they want is the word "eval" in the first parameter and then a string array of functions, and or commands you wish to eval
var value = await webViewer.InvokeScriptAsync("eval",
new string[]
{
"functionName(functionParams)"
});
Having worked with Microsoft APIs for a few years now I am convinced that this is not the intended way of consuming this function and is a bit of a hack. Unfortunately if you want to consume JavaScript this is the only way that I know that works currently.
Anthony,
Try to check your own suggestion:
await webViewer.InvokeScriptAsync("eval",
new string[]
{
"functionName(functionParams)"
});
or:
await webViewer.InvokeScriptAsync(functionName, new string[]{ functionParameters });
The same as Microsoft suggests, just you are limiting a function name by one ("eval") - not necessary. Trust me, you can use any function name, as I am now with UWP and before with windows phone hybrid apps.
The question is already 4 years old, but I'm coming to see why you were getting an empty string as a result.
In your example, the functions in JavaScript return integers while the expected value is of type string.
By modifying these functions and returning a string like this:
string htmlFragment = #"<html><head><script type='text/javascript'>" +
"function a(){return '10';};" +
"function b(){return '20';};" +
"function c(){return '30';};" +
"</script></head><body>" +
"<div id = 'myDiv'>I AM CONTENT</div></body></html>";
We get the good result on the way back.
I am running an program that uni-directly copies from source to destination. The following script runs in conjunction and skips any files with a "date modified" equaling the same day the program is running.
I'd like to modify the script to skip any files with a "created" date equaling today's date and allow any other files regardless of "modified" date.
Essentially, If DateCreated=Today Then Skip
Below is the script I am currently using. I just can not get the right syntax to use creation time verses modified time.
Thank you in advance,
Function Description(ScriptType)
Description = "Ignores any source files modified today. Not used on Restore."
ScriptType = 2
End Function
Sub RunBeforeFileCompare(Filename, ByRef Skip)
' Ignore if this is a Restore
If SBRunning.Restore Then Exit Sub
' See if the file date is the same as todays date, skip if so
If DateDiff("d", SBRunning.GetFileDateTime(Filename, TRUE), Date) = 0 Then
Skip = TRUE
Else
Skip = FALSE
End If
End Sub
The following example illustrates the use of the GetFile method.
filespec: Required. The filespec is the path (absolute or relative) to a specific file.
An error occurs on GetFile method if the specified file does not exist.
JScript
function ShowFileAccessInfo(filespec)
{
var fso, fle, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
fle = fso.GetFile(filespec);
s = fle.Path.toUpperCase() + "<br>";
s += "Created: " + fle.DateCreated + "<br>";
s += "Last Accessed: " + fle.DateLastAccessed + "<br>";
s += "Last Modified: " + fle.DateLastModified
return(s);
}
VBScript
Function ShowFileAccessInfo(filespec)
Dim fso, fle, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set fle = fso.GetFile(filespec)
s = fle.Path & "<br>"
s = s & "Created: " & fle.DateCreated & "<br>"
s = s & "Last Accessed: " & fle.DateLastAccessed & "<br>"
s = s & "Last Modified: " & fle.DateLastModified
ShowFileAccessInfo = s
End Function
How can I convert a python timestamp with javacript
from 2014-07-28T20:45:04.271935
to 1.6.2014 (20:45)
I tried to use the builtin parse function from javascript, but it seems to mix up things..
out = new Date(context);
out = out.getDay() + ". " + out.getMonth() + ". " + out.getFullYear() + " (" + out.getHours()+ ":" + out.getMinutes() + ")";
If you work with date and time intensively in your application I'd recommend you to use Moment.js library for painless conversions:
moment('2014-07-28T20:45:04.271935').format('D.M.YYYY (H:m)');
// Will return "28.7.2014 (20:45)"
moment('2014-07-09T20:45:04.271935').format('DD.MM.YYYY (H:m)');
// Will return "09.07.2014 (20:45)"
And if you need to format the date and time only in one place then just build the string manually as you did in your code example.
I have a Python script that returns me a calculated date time in XML format like below:
<prev><date>2012,07,16</date><time>22:00:00</time></prev>
Though I can change the format but my issue is that when I try creating a JS date object using the value returned - I get 'Invalid date':
$.ajax({
async: false,
type: "POST",
url: "/cgi-bin/prev_hour.py",
success: function(xml)
{
pdate = $(xml).find('date').text();
ptime = $(xml).find('time').text();
//alert prints correct date time ex 2012-07-16 22:00:00
},
error:function(xhr,err,html)
{
alert("Failed\nreadyState: "+xhr.readyState+"\nstatus: "+xhr.status + "\nresponseText: "+xhr.responseText);
}
var max_date = new Date("'" + pdate + ptime + "'");
alert(max_date);
I tried a couple of possibilities like Python script returning in various format:
<prev><date>2012/07/16 </date><time>22:00:00</time></prev>
<prev><date>2012,07,16 </date><time>22,00,00</time></prev>
But still I get invalid date when trying to create a JS date object?
Please let me know the correct way to implement it.
You don't need the extra set of quotes in your date string, and you will need a space between the date and time components, try:
new Date(pdate + " " + ptime);
Try using amazing lib for dates called Moment.js
moment("2012/07/16 22:00:00")
from there you can achieve everything with dates.
This:
var max_date = new Date("'" + pdate + ptime + "'");
Should be:
var max_date = new Date(pdate + ' ' + ptime);
Next time you run into such issues put an alert on the value you are sending to the function and see what it looks like.