Skip to content

Instantly share code, notes, and snippets.

@ridalabbar
Last active July 3, 2021 11:57
Arabic Time Minutes to Hours Convertor
function timeInArabic(timeInMinutes) {
let hours = Math.floor(timeInMinutes / 60);
let minutes = timeInMinutes % 60;
let timeInArabicStatement = '';
if(hours == 1) {timeInArabicStatement = 'ساعة';}
else if (hours == 2) {timeInArabicStatement = ' ساعتان';}
else if (hours > 2 && hours < 10) {timeInArabicStatement = hours + ' ساعات';}
else if (hours > 10) {timeInArabicStatement = hours + ' ساعة';}
if(timeInMinutes % 60 != 0 && hours > 0) timeInArabicStatement += ' و';
if(minutes == 1) {timeInArabicStatement += 'دقيقة';}
else if (minutes == 2) {timeInArabicStatement += 'دقيقتان';}
else if (minutes > 2 && minutes <= 10) {timeInArabicStatement += ' ' + minutes + ' دقائق';}
else if (minutes > 10) {timeInArabicStatement += ' ' + minutes + ' دقيقة';}
return timeInArabicStatement;
}
// example of calling the function
console.log(timeInArabic(150));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment