Date Range Picker - Calendar Heading Localization Format - localization

When applying localization to the angular date range picker the date format is incorrect for the calendar heading. The date should be displayed as YYYY, MM but is displayed as MM, YYYY. I'm using moment().format('ll') to display the localized format in the text input but using the date range picker locale.format option doesn't have any affect on the calendar date format.
var dateOptions = {
locale: {
format: 'll'
}
};

Updated daterangepicker.js as follows:
// added new var around line 719
var calMonth = moment([calendar[1][1].year(), calendar[1][1].month()]).format("L");
// line 754
html += '<th colspan="5" class="month">' + calMonth + '</th>';

modify daterangepicker.js
line 707
var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
modify it to the format you want.
var dateHtml = calendar[1][1].format("YYYY") + this.locale.monthNames[calendar[1][1].month()];

Related

Date formatting for next available date in Swift [duplicate]

This question already has answers here:
Convert string with unknown format (any format) to date
(2 answers)
Closed 5 years ago.
I'm currently downloading fixture lists for a sports app from a third party website that runs the league, so the data I have to work with is restricted.
I'm trying to implement a feature that displays the next upcoming fixture.
My problem is the dates being retrieved look like this:
"Sat 9th Sep 17" and "Sat 24th Mar 18" for example.
I've tried numerous date formats in the DateFormatter that I know of and can't find anything that uses this specific format.
If I try to use the Date from string method in the date formatter with one of the above strings I get a nil value.
I have an array of fixtures, each with their own dates. I need to compare each of these to the current date to figure out which is next in line.
My temporary fix for this was just to loop through the fixtures and as soon as one did not have a result to display that as the next fixture. Obviously this doesn't work when a game may not have been played for whatever reason.
What would be the best way to deal with this?
Basically you would just need to convert the current date to the same format as the date you get from your third party website (or the opposite) so you can compare them easily:
let currentDate = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EE MMM"
let firstPartStringDate = dateFormatter.string(from: currentDate)
dateFormatter.dateFormat = "yy"
let lastPartStringDate = dateFormatter.string(from: currentDate)
let day = Calendar.current.component(.day, from: currentDate)
let formatter = NumberFormatter()
formatter.numberStyle = .ordinal
guard let ordinalDay = formatter.string(for: day) else {
return
}
let finalDateString = firstPartStringDate + " \(ordinalDay) " + lastPartStringDate
print(finalDateString)
And for today's current date you would get the exactly same format as the one you get from the third-party website :
Sun Sep 17th 17
UPDATE: Here is how you could convert the String you get from the third-party website to a Date, and then compare it with the current date. This solves the problem of having the st, nd, rd and th inside the String at first.
// This is the string you get from the website
var webDateString = "Sat 9th Sep 17"
// First, remove the st, nd, rd or th if it exists :
if let stSubrange = webDateString.range(of:"st") {
webDateString.removeSubrange(stSubrange)
} else if let ndSubrange = webDateString.range(of:"nd") {
webDateString.removeSubrange(ndSubrange)
} else if let rdSubrange = webDateString.range(of:"rd") {
webDateString.removeSubrange(rdSubrange)
} else if let thSubrange = webDateString.range(of:"th") {
webDateString.removeSubrange(thSubrange)
}
// Now convert the string to a date :
dateFormatter.dateFormat = "EE MMM dd yy"
guard let formattedDate = dateFormatter.date(from: finalDateString) else {
return
}
// You can now compare formattedDate and the current date easily like so :
let currentDate = Date()
if formattedDate < currentDate {
// Do something interesting here :)
} else {
// Do something else!
}

Date formatter subtracting year by one and changing day when converting from string to date [duplicate]

This question already has an answer here:
Swift date formatting
(1 answer)
Closed 5 years ago.
I'm using dateformatter to convert a date between string and date types for inputing a date via a UIDatePicker. When the view loads if a saved string of the date exists it's put into the date text field (and entered correctly). When dateformatter converts the string into a date it returns the wrong date. (Always December 20ish of the previous year.)
let df = DateFormatter()
df.dateFormat = "MM/dd/YYYY"
func setDatePickerDate() {
if dobText.text != "" {
print("\n\nSaved date as string: \(dobText.text!)")
let testDate = df.date(from:dobText.text!)
print("Saved date converted to date: \(testDate!)")
print("Date converted back to string: \(df.string(from: testDate!))")
dobPicker?.date = df.date(from: dobText.text!)!
}
}
Which returns:
Saved date as string: 06/07/1977
Saved date converted to date: 1976-12-19 06:00:00 +0000
Date converted back to string: 12/19/1976
and if I keep running the setDatePicker function it keeps subtracting a year and changing the day.
Saved date as string: 12/19/1976
Saved date converted to date: 1975-12-21 06:00:00 +0000
Date converted back to string: 12/21/1975
Saved date as string: 12/21/1975
Saved date converted to date: 1974-12-22 06:00:00 +0000
Date converted back to string: 12/22/1974
Etc.
edit: Just noticed it cycles the days between 19-25 adding 1 to the date until it hits 25 then returning back to 19.
Change your format string to: "MM/dd/yyyy" and it should work as written.
Capital "Y" in Unicode Technical Standard #35 Locale Data Markup Language refers to "week of year" based calendars in which the year transition occurs on a week boundary. For most applications you want lower case "y", which refers to standard numeric calendar year.

Google spreadsheets convert text date to spreadsheet date

I've imported a csv file in my spreadsheet which containing a date in this format
yyyymmdd
(20161018 for today )
To use this date in my new spreadsheet I use this formula
CELL T49 = 20161018
=DATEVALUE(CONCATENATE(left(T49;4);"/";mid(T49;5;2);"/";right(2)))
I was wondering if there is a more simple way to convert a text date to a spreadsheet date
It becomes relevant because you can not use concatenate in an "ArrayFormula"
You could make your own function (cut/paste the script below into Tools>Script Editor) and then use =DATEME(T49)
function DATEME(input) {
var input = input.toString();
var year = input.substring(0,4);
var month = input.substring(4,6);
var day = input.substring(6);
//JavaScript months are 0-11
return new Date(year,month-1,day) ;
}
=DATEVALUE(TEXT(20161018;"0000-00-00"))
next format cell as date.
TEXT function converts number format to string looking like date:
2016-10-18
DATEVALUE converts a provided date string in a known format to a date value

How to format Date(Time)Picker value to a date only string?

My default date setting in Fiori launchpad is "dd.MM.yyyy, HH:mm". Whenever I get the date from the date picker placed in view, I am getting the date in the above format.
Now I want to send this date to backend through ODataModel which generally accepts date in XML date format (e.g. "2014-12-30"). I tried the below code, but it did not work.
var fromDate = this.byId("fromDate").getValue(); // "30.12.2014, 10:36"
var oDateFormat = DateFormat.getDateTimeInstance({ pattern : "yyyy-MM-dd" }); // DateFormat required from "sap/ui/core/format/DateFormat"
var subFromDate = oDateFormat.format(new Date(fromDate)); // "0NaN-NaN-NaN".
When I check in debugger mode, the value in subFromDate is "0NaN-NaN-NaN". Please provide your valuable suggestions.
You can use getDateValue() method instead of getValue.
var fromDate = this.byId("fromDate").getDateValue(); // returns a JS date object
var oDateFormat = DateFormat.getDateTimeInstance({ pattern : "yyyy-MM-dd" }); // DateFormat required from "sap/ui/core/format/DateFormat"
var subFromDate = oDateFormat.format(fromDate); // "2014-12-30"
The fromDate isn't correct. When I using new Date("30.12.2014, 10:36"), the console show message " Invalid Date".
I look for more information about "Date" from MDN(link).
new Date(dateString)
String value representing a date. The string should be in a format recognized by the Date.parse() method. The dateString could be '30 12 2014 10:36'.
So you need to replace the '.' and ',' to ' ' in fromDate first.
You can use display format and value format properties of date time picker.
new sap.m.DateTimePicker("ED",{
valueFormat: "yyyy-MM-ddTHH:mm:ss",
displayFormat: "dd-MM-yyyy HH:mm:ss"
});
you can easily get the values using
sap.ui.getCore().getControl("ED").getValue();

NSDateFormatter equivalent in Titanium / Convert date in specified format in Titanium

I'm working with the date and time in my Titanium based iOS application.
My issue is, I'm getting the time in the below format:
Wed Jan 16 2013 17:32:40 GMT+0530 (IST)
I want to change it like:
Jan 16, 2013, 05:32 pm
In iOS there is NSDateFormatter for doing this.
What I did :
Currently I'm doing it manually using split and switch cases, but it fails if the input time format changes, then I need to re-write the code for the changed format.
I searched alot in Titanium Docs, but didn't get any solution.
I asked same question on their forum, didn't get any reply till now.
Is there is anyway to do this in Titanium?
Please help, Thanks in advance.
Look for moment.js JavaScript module for date formatting
I didn't find any alternatives for the NSDateFormatter in Titanium.
I tested the Moment.js, but it didn't worked for my case.
I implemented a JavaScript function for achieving my output.
/**
* Function for formatting the date and time
* #param {Object} dateTime
*/
function formatDateTime(dateTime)
{
var arr = dateTime.split(' ');
var convertedDate = arr[1]+' '+arr[2]+', '+arr[3];
var convertedTime = arr[4];
var returnValue = convertedDate+', '+convertedTime;
return returnValue;
}
Edit on 27 Feb 2014
After facing the JavaScript date formatting issue on different occasions, I finally developed my own JavaScript module, this module will format the JavaScript Date object to Specified formats. You can find it here : MMP_DateTime
I write one function which will convert date as per my requirement as given below
var getRequiredDate = function(date) {
var monthList = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear(); // Use standard date methods
var newdate = monthList[month] + ' ' + day + ", " + year;
Ti.API.info("Date :" + newdate);
};
Hope this helps you.

Resources