Is there a simple, established way to allow free-form date entry on a web page and parse the input text to get a Date value? We have a new requirement to go from using a date picker to allowing free-form date entry. So the user could theoretically enter any of the following:
12/7/41
12-7-1941
Dec 7, 1941
And we would have to attempt to parse it and make a date out of it.
I have attempted to find something online but the closest is this JQuery widget which doesn't do the free-form thing. There's also DateJS but it looks unfinished and development stopped in 2008. I'm just wondering if there's anything else out there.
MomentJS has what you are looking for. It's a robust library with almost all your time and/or date needs handled.
MomentJS Parsing: http://momentjs.com/docs/#/parsing/
Related
I have 3 date and time fields (its date only).
But I want to limit the user not to be able to select future date.
I mean dates after today's couldn't be selected in the date picker.
How can I do it?
Crm datetime field doesn't support this type of functionality. You'll need to create your own html webresource and use a well-known library / control such as jquery datepicker.
Once you have the resource in place syncing the picker value with the hidden datetime value should be relatively easy using the form onload and onsave events.
You have to write a validator, either in plugin or JavaScript (or business rules), or perhaps both.
JS only works in the forms but has the possibility to give a prettier error message, with the business rules you can have a valitation which gives messages inline. If you only add data using the GUI, it might be enough to just use JS/business rules but if data can come any other way I would secure it with a plugin as well.
The validator is pretty simple, retrieve the field and compare it with a date object today. It could be a bit worse if there are a lot of timezones involved, we don't like timezones....
I should preface this post by saying that I am a very elementary developer with a generic IS degree. Without going into too much detail, I was given a moderately large web application from an interning software engineer to support an enhance if need be. It was written primarily in Python, JavaScript and HTML5 and utilizes a Google Map API to visually represent the location and uses of given inputs. This leads me to my question.
There is a date picker modal that the application/user utilizes. They pick a START and END date, in the default format YYYY-MM-DD (if the user does not use that exact format (i.e. 2015-09-29) the date picker will not work), and the application then goes to the DB and picks the given inputs between those dates and represents them on the map. I have been told that, for usability, I have to make the program accept multiple date formats (i.e. September 29 2015, 09-29-2015, 9-29-2015, 9/29/2015). How would I go about doing this?
You can use Javascript to give the user the feedback that the correct format(s) is being used. But if you are taking any data to your server be sure verify the data on the server.
To verify the correct dataformat you can use Regular expressions and check if any format is correct. You should iterate through all allowed possibilities until one is found correct.
Your best bet from the user-experience standpoint is not to try and parse multiple formats but to normalize the input being accepted.
For dates, wouldn't you rather use a calendar picker instead of manually typing in the dates?
Have a look at this jQuery solution, or you can Google, there are plenty that don't use jQuery, and you can usuaslly specify the outupt format so you get the format you require.
Here's an example doing what you want: http://jsfiddle.net/ezygkgxt/
HTML
<label>Date: <input name='date' /></label>
<input type='hidden' id='actualDate' />
JS
$("input[name='date']").datepicker({
altFormat: "yy-mm-dd",
altField: "#actualDate"
});
$("input[name='date']").change(function(){
window.alert("The current chosen date is: "+$("#actualDate").val());
});
I am having some troubles dealing with the SharePoint date system, and I was hoping to find some advice here. The problem I am facing is that every time I use JS to save a new item to my SharePoint list, the date that I pass (simply yyyy-mm-dd, no time included) is saved as a day earlier than I intended. I am almost certain I know why this is- the timezones are different. While I am at -4, the server is at +1. I am not familiar enough with how SharePoint receives and stores dates to know how I should proceed to get the dates to work properly. Any suggestions would be appreciated.
SharePoint datehandling 101 is that it always store the dates in UTC, that is +-0. When using the gui SharePoint automatically translates the time to your local time. Hence, the date and time you get is the UTC version and when saving datetimes through an API you must ensure if the API is localized or not, if it isn't then store the datetime as UTC.
I need to write a web application that show events of people in different locale. I almost finished it, but there're 2 problems with date:
using date javascript object, the date depends on user computer settings and it's not reliable
if there's an event in a place with dfferent timezone respect user current position, i have to print it inside (). Is it possible in javascript to build a date object with a given timezone and daylight settings?
I also find some workaround, such as jsdate and date webservices, but they don't overcome the problem of having a javascript object with the correct timezone and daylight settings (for date operation such as adding days and so on).
A couple of things to keep in mind.
Store all event datetimes in UTC time
Yes, there is no getting around this.
Find out all the timezones...
...of all the users in the system. You can use the following detection script: http://site.pageloom.com/automatic-timezone-detection-with-javascript. It will hand you a timezone key such as for example "America/Phoenix".
In your case you need to store the timezone together with the event, since a user may switch timezone - but the event will always have happened in a specific one. (argh)
Choose your display mechanism
If you want to localize your event dates with Javascript, there is a nifty library for that too (which can use the keys supplied with the previous script). Here: https://github.com/mde/timezone-js.
with that library you can for example do this:
var dt = new timezoneJS.Date(UTC_TIMESTAMP, 'America/New_York');
or
var dt = new timezoneJS.Date(2006, 9, 29, 1, 59, 'America/Los_Angeles');
where UTC_TIMESTAMP for example could be 1193855400000. And America/New_Yorkis the timezone you have detected when the event took place.
The dt object that you get from this will behave as a normal JavaScript Date object. But will automatically "correct" itself to the timezone you have specified (including DST).
If you want to, you can do all the corrections in the backend - before you serve the page. Since I don't know what programming language you are using there, I cannot give you any immediate tips. But basically it follows the same logic, if you know the timezone, and the UTC datetime -> you can localize the datetime. All programming languages have libraries for that.
You're missing the point of a Date object. It represents a particular point in time. As I speak, it is 1308150623182 all over the world. Timezone only comes into play when you want to display the time to the user. An operation like "adding a day" does not involve the time zone at all.
One possibility might be to use UTC date and time for everything. That way, there is nothing to convert.
Another is to have your server provide the time and date. Then you don't have to depend on the user to have it set correctly, and you don't have to worry about where your user's timezone is.
Use getUTCDate(), getUTCHours(), ... instead of getDate(), getHours(),...
getTimetoneOffset() could be useful, too.
I'm looking for a way to have a textbox that allows users to type in a date in any format and turns around and formats that date in a 'mm/dd/yyyy' format. So the user could type in "Today" and it would turn the date as 02/24/2009 or they could type in Wednesday Feb 24 and formatting would automatically pick up. Remember the Milk does this (but I believe server side). This is asp.net so I could do via ajax web service call but I would prefer to do this via Javascript. I'm looking for a general technique or existing library to help with this.
Check out http://www.datejs.com/