xdate icon indicating copy to clipboard operation
xdate copied to clipboard

corrupted locales in react native

Open tobiaseisenschenk opened this issue 6 years ago • 2 comments

I am not sure if it is in the scope of this library, but I wanted to mention it here since I had the issue today.

We used XDate in a react-native app. Any formatting via .toString('M/d/yy h(:mm)TT'); as shown in the docs would cause the app to crash (not in the simulator, only on the device). The reason was the locales object missing the properties amDesignator and pmDesignator.

Feel free to close the issue, since XDate works fine inside browsers (https://jsfiddle.net/sfd05Lwn/1/). I fixed our issue by simply calculating AM/PM manually.

tobiaseisenschenk avatar Aug 22 '19 15:08 tobiaseisenschenk

Hi @tobiaseisenschenk, can you better detail how you solved it?

erbud avatar Apr 27 '21 18:04 erbud

Hi @tobiaseisenschenk, can you better detail how you solved it?

Well my dirty hack as I said is to not let xdate do the formatting for me. I parsed the time in 12h format like this:

function parse12h(xDate) {
	let hours = xDate.getHours();
	let minutes = xDate.getMinutes();
	let ampm = hours >= 12 ? 'PM' : 'AM';
	hours = hours % 12;
	hours = hours ? hours : 12; // the hour '0' should be '12'
	return (
		hours + ':' +
		(minutes < 10 ? '0' + minutes : minutes) +
		' ' + ampm
	);
}

tobiaseisenschenk avatar May 06 '21 13:05 tobiaseisenschenk