Extjs date format issue safari firefox - google-chrome

Dates are stored in the format, YYYY-mm-dd hh:mm:ss in the database.
e.g. 2014-07-03 00:00:00
But I want my Ext.Field.Date to have the format:
Y-m-d H:i
As per my component set up:
xtype: 'datefield',
id: 'p_p_start',
fieldLabel: 'Planned Start',
name: 'plannedstart',
allowBlank: false,
vtypeText: 'Date not valid',
format: 'Y-m-d H:i',
It is quite reasonable of me to want to be able to display the date in browsers other than just Chrome. To-date, FireFox and Safari will display nothing.
I've looked at a similar issue on SO which proposed support of all browser by splitting and reassembling the string format in a variation of:
var c=Ext.getCmp('p_p_start');
var st_date = "2014-05-08";// with alt formats changed Y-m-d, leaving time out diags
var dateParts = st_date.split(/-/);
var d = new Date(dateParts[0],parseInt( dateParts[1], 10) -1,dateParts[2]);
console.log("Date parts= " + dateParts);//Date parts= 2014,05,08
c.setValue( d ); //NOPE!
I was very happy with progress in Chrome (no problems at all) but have yet to succeed in getting anything working in FF or Safari (not tried IE but it has to work in that also). So, in summary, the question is,
How do I get date formats in all browsers to work with the format Y-m-d H:i using setValue?
Many thanks in advance.
Kevin

A date field's internal value is a JavaScript Date Object, which is not tied to a specific format. The format config simply defines the display and input format of the field.
You can use setValue with a string, but only if the string already conforms to your defined format.
In your case the problem seems to be converting a date string value with a different format which was received from the server/database to a Date object.
Have a look at the Ext.Date singleton, specifically its function Ext.Date.parse, to achieve that:
var st_date = "2014-05-08";
var dateObj = Ext.Date.parse(st_date, "Y-m-d");
Ext.getCmp('p_p_start').setValue(dateObj);
var st_date2 = "2014-07-03 00:00:00";
var dateObj2 = Ext.Date.parse(st_date2, "Y-m-d H:i:s");
Ext.getCmp('p_p_start').setValue(dateObj2);

Related

Safari shows invalid date while using moment(x).year() in DD-MM-YYYY format. while Chrome works fine

I am using moment.js with Angular 5.
Encountered a strange problem that with Chrome, it works fine but in SAFARI while debugging I see the values as NaN or "Invalid Date"
date = 18-05-2019 // DD-MM-YYYY format
year = moment(date).year(); // getting year as "Invalid Date" or NaN
Just pass the format you have to moment so it know how to convert your date:
let date = '18-05-2019'
let year = moment(date, 'DD-MM-YYYY').year();
console.log(year)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.js"></script>

How to put a / in vaadin-date-picker

I am using a vaadin-date-picker with polymer. I would like to put the right slash by default when the user types in a date in US format. So if the user types 01152019, it should auto format the date to 01/15/2019. Right now if I enter date without the / , it wont take recognize the value.
You should set the parseDate method of the i18n property of your date picker so that it does what you want, for example, if you only wanted to accept date strings in US format but without slashes or hyphens you could do something like this:
const datePicker = something; // you probably did something like this.querySelector() to get it
datePicker.i18n = {
// you can also set methods to format the date or the title and a few other things
parseDate: dateString => {
let month = parseInt(dateString.subString(0,2));
let day = parseInt(dateString.subString(2,4));
let year = parseInt(dateString.subString(4,8));
return {day, month, year};
}
};

Highcharts with external CSV $.get - No xAxis date

I'm trying to create a spline chart using this CSV:
slave_id,date,time,rtc_temp,temp1,temp2,temp3
1,2017/12/26,16:42:59,21,11.50,13.13,5.88
2,2017/12/26,16:43:29,21,14.13,20.63,99.99
1,2017/12/26,16:44:00,21,11.50,13.13,5.88
2,2017/12/26,16:44:30,21,14.13,20.63,99.99
1,2017/12/26,16:45:01,21,11.50,13.13,5.88
2,2017/12/26,16:45:31,21,14.13,20.63,99.99
1,2017/12/26,16:46:02,21,11.50,13.13,5.88
2,2017/12/26,16:46:32,21,14.13,20.63,99.99
As you can see here [IMAGE], the graph is showing the date and time, but the x Axis is not accepting the date / time.
Ive tried using date.UTC, but that did not work either. Can someone point me in the right direction?
https://jsfiddle.net/asvoy6b9/ [not working due to CSV missing]
Full code [Hastebin]
I see that date variable in your code is a string:
// all data lines start with a double quote
line = line.split(',');
date = line[1] + " " + line[2];
(...)
RTC.push([
date,
parseInt(line[3], 10)
]);
If you choose to construct the point's options as an array of two values and the first value is a string then it's treated as its name property (not x).
Explanation: https://www.highcharts.com/docs/chart-concepts/series
In that case Highcharts assigns subsequent integers as x values for all points (that's why there're values like 00:00:00.000 (1 Jan 1970), 00:00:00.001 etc.).
You need to parse your date to timestamp. You can use Date.UTC() (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC) or some other function for this.
I've managed to get it working with Date.UTC using the following code:
var yyyymmdd = line[2].split("-"); //Split the date: 2017 12 16
var hhmmss = line[3].split(":"); //Split the time: 16 11 14
var date = Date.UTC(yyyymmdd[0], yyyymmdd[1] - 1, yyyymmdd[2], hhmmss[0], hhmmss[1], hhmmss[2]); //Stitch 'em together using Date.UTC

Converting Phonegap app datetime fields to work on ios7

So I just found out that the datetime input fields I use all over my app are no longer working on IOS7, so I found that the datetime-local input type is still supported. Timezone is not important to the function of my app, so this is ok. The problem is, the code I was using to populate and retrieve the date values from the input fields does not work. Here is my code:
$("#date").val(pv.When);
To set it, where date is the id of my input and pv.When is a datetime object
theVisit.When = new Date($("#date").val());
To retrieve it, right now neither do anything, the field is empty when i load the form, and the value does not save. Do I need to do anything special to make this work?
OK, what I did was this, I wrote 2 utility functions, one to set the value of the datetime-local field and one to get the value out as a date. You will notice as part of the fix I am using the Moment.js date helper library.
Here are my 2 functions:
function getDateTimeForPicker(d) {
var offset = d.getTimezoneOffset() / 60;
d.setMinutes(d.getMinutes() - d.getTimezoneOffset())
return d.toISOString().replace("Z", "");
}
function getDateTimeFromPicker(d) {
var m = moment(d);
var ret = m.toDate();
return ret;
}
so I can set as easy as :
$("#dateTimeBox").val(getDateTimeForPicker(new Date()));
This is tested and working fine on iOS7

TimeDelta class in ActionScript?

Is there any ActionScript class which represents "durations of time", similar to the TimeDelta class in Python?
Edit: Thanks for the responses. I should clarify a bit, though: I want be able to ask questions like "how many weeks are between date0 and date1" or "let x represent "one day". What is date2 + x?"
I know I can do all this by representing dates as timestamps... But I'm hoping to find something nicer.
I posted a full AS3 port of the .NET TimeSpan class on this question, which sounds exactly like what you need.
// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);
// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);
You can use time() in the Date class to get unix era milliseconds and use that for time delta.
If you subtract two dates:
var dateDiff = date1 - date2;
dateDiff will hold the number of milliseconds between the two dates. You can then convert from milliseconds to whatever useful number you like.
I don't think there is a class which measures change in time in Actionscript 3. According to this blog post on Adventures in Actionscript, timing is very inaccurate in the Flash player on the web. That post is pretty informative and has a class called SuperTimer that might help you. You might want to keep this inaccuracy in mind if using solutions posed by Justin Niessner and toastie.