Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corrupted locales in react native #42

Open
tobiaseisenschenk opened this issue Aug 22, 2019 · 2 comments
Open

corrupted locales in react native #42

tobiaseisenschenk opened this issue Aug 22, 2019 · 2 comments

Comments

@tobiaseisenschenk
Copy link

tobiaseisenschenk commented Aug 22, 2019

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.

@erbud
Copy link

erbud commented Apr 27, 2021

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

@tobiaseisenschenk
Copy link
Author

tobiaseisenschenk commented May 6, 2021

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
	);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants