Proper way to give id to any element - javascript

I am making a project to select date and time for making appointment( img below). I am giving id to label as combination of date and time. for example id
"2015-08-24 10:00 am" is given to label showing time 10:00 am.
this is mandatory for me to give id like this to highlight all label falling under this service time slot.(in this case service time slot is of 170 min)
till now it is working fine. but can it cause some problem in future for me to give id like this???
sorry for my poor english....................

can it cause some problem in future for me to give id like this?
Maybe, it depends on how you use them. But it's invalid, id values cannot contain spaces.
Instead of using id, I'd suggest using a data-* attribute, such as data-value="2015-08-24 10:00 am".
If I were going to use that value in JavaScript, I'd also probably put that value in the standard JavaScript form (as of the most recent spec, this is a subset of ISO-8601; prior to that, the spec had an error in it which make it not quite a subset): 2015-08-24T10:00 (plus any timezone if relevant).

Related

How can I subtract two time values in Adobe Sign?

I need to get the difference in hours and minutes of two times. For example 8:30AM and 2:14PM. I need to be able to subtract these to hours in Adobe Sign Formula expression. The supported function seem to support date based fields and not necessarily work right with only time. Here is the support page:
Add calculated fields to a form
I tried using datePart(part, date) and parsing first the hour and then the minutes. The problem is that this works if the value is a PM time (3:00PM) but if the value is an AM time (7:30AM) the function returns 0 instead of 7 (in the hours case)
datePart("h", "08:00:PM") = 8
datePart("h", "07:30:AM") = 0
I found out how to do this:
When creating the fields, make sure they are of type text and that the properties are as shown in the following image:
Notice the date format is a custom and with format h:nn tt, meaning that it only accepts values like 12:25 PM and 1:35 AM (no lower case am or pm). So suppose you have two fields like these: time_test1 and a time_test2, the third field instead will contain the number of hours will have this properties setup:
So, clicking on the F(x) in order to expand the formula expression, you need to put the following formula: dateDiff("h", [time_test2], [time_test1])
Also, click on Check syntax to make sure that it’s valid
Here is how it would look when I sign:
I hope this can be useful to others.

How can I format a string with moment js to suppress minutes if the time ends with ":00"?

I need to format two moment objects to display a time range to users, eg:
6:45PM-9:30PM
I know I can get this with
`${time1.format('h:mmA')}-${time2.format('h:mmA')}`
but I want to suppress minutes when either the start or end time is on the hour, eg:
6:45PM-10PM (instead of 6:45PM-10:00PM)
7PM-9:30PM (instead of 7:00PM-9:30PM)
7PM-10PM (instead of 7:00PM-10:00PM)
I can check to see if the minutes are 0 before and change my formatting string based on that, but that seems inelegant I'd like to do this only using .format if possible. Haven't found anything in the formatting docs about this.
.format does not provide that you want inbuilt. Rather you can use string replace function instead.
`${time1.format('h:mmA').replace(":00","")}-${time2.format('h:mmA').replace(":00","")}`

Sharepoint Action List - Due date wrongly converted probqbly due to timezone

I have deployed an action lis with a kind of dashboard. Through this, I would like to highlight the overdue action by adding the status on a dedicated column via javascript. My full script works well except the line where I want to get the Due Date.
For trying to identify the issue, I have simply copied the Due Date in an other column (check column), and the result is surprising!!!
Examples:
Due Date as displawed in the pop-up > Check column interpreted by the JS code
-30/07/2016>27/07/2016 22:00:00
-16/08/2016>17/08/2016 22:00:00
-01/08/2016>03:08:2016 22:00:00
Find hereafter an extract of the code:
var Status = oListItem.get_item('Status');
duedate = oListItem.get_item('DueDate');
oListItem.set_item('Check', oListItem.get_item('DueDate'));
It seems that the issue is related to the orignial Due Date column, qnd linked to a wrong conversion.
Does someone have an idea how to correct this issue?
I have found a solution or work around:
Create a calculated field which recreate the date from the Due Date field
In the JS, get the string from the calculated field, and then split it, et recreate the date with the JS code
Have fun!

Format Date and Time into DTG

I have a row where users enter in various type of data in the date in there are different formats that I want to standardize. For example
12/21/2014 1900
This is one possible format I would like for the <td> to change it into DTG format which is
DD-HHMMZ-MMM-YY
Day, Hours in 24 format, Minutes, instead of p.m./a.m. I need Z for zulu, Month and year
How do I have this change once the user enters the data? I was looking at the onchange for javascript but I am not completely sure.
I'm assuming what you're asking is how to force the input to update after the user enters the date information. I'm assuming you know how you're going to format the date based on the given input.
This example shows you how to use jquery's .change() to update the input after something is entered. http://jsfiddle.net/Z5B25/
The basic code looks like:
$('.date').change(function(){
$(this).val('Computed/formatted Date');
});
Though this is not specific to your usage.

Moment.js 2 different date strings when i parse using moment gives same value

I am parsing 2 different date strings
var d1 = '2014-02-01T00:00:00.000+0530'
var d2 = '2014-02-23T00:00:00.000+0530'
when i parse them using moment
alert(moment(d1, 'YYYY-MM-dd"T"HH:mm:ss.fffffff"Z"').toDate());
alert(moment(d2, 'YYYY-MM-dd"T"HH:mm:ss.fffffff"Z"').toDate());
both of them print Sat Feb 1 2014 xxxxx
what is wrong with it??
here is the link to the fiddle i created
jsfiddle
I think your moment formatting string is causing you the problem. If I remove this, the dates do not print as the same.
http://jsfiddle.net/K5ub8/7/
EDIT: The specific issue is you are using dd for day, instead of DD. http://momentjs.com/docs/#/parsing/string-format/
Here is your fiddle fixed:
http://jsfiddle.net/K5ub8/9/
However, I am not 100% sure about the fractional seconds, I believe it is SSS instead of fffffff but I would test this if you need to cater for fractional seconds.
I should mention that if you are converting it back into a JavaScript date object anyway with toDate(), then you don't really need the moment formatting parameter as the date will be formatted in JSON Date format.
I would question why you would want to generate a moment formatted date, and then convert it back to JavaScript, a normal practice might be to receive a date in JavaScript format, then create a moment object which you can use to perform calculations and display in a nice user friendly way.
Simple answer: your format was off a bit.
http://jsfiddle.net/K5ub8/8/
After tweaking the format to be 'YYYY-MM-DDTHH:mm:ss.SSSZZ' rather than 'YYYY-MM-dd"T"HH:mm:ss.fffffff"Z"' it worked just fine. When you're trying to debug issues like this, it's always good to keep the format in a separate variable so you can use the same format that you're trying to parse out to display what you're getting. Had you done that, you would have noticed that 'YYYY-MM-dd"T"HH:mm:ss.fffffff"Z"' was messed up due to it printing out 2014-01-Fr"T"11:32:03.fffffff"-08:00". Which obviously isn't quite right.

Categories

Resources