81 lines
2 KiB
TypeScript
81 lines
2 KiB
TypeScript
class Extension {
|
|
public static ToThaiMonth(value: number) {
|
|
switch (value) {
|
|
case 1:
|
|
return "มกราคม";
|
|
case 2:
|
|
return "กุมภาพันธ์";
|
|
case 3:
|
|
return "มีนาคม";
|
|
case 4:
|
|
return "เมษายน";
|
|
case 5:
|
|
return "พฤษภาคม";
|
|
case 6:
|
|
return "มิถุนายน";
|
|
case 7:
|
|
return "กรกฎาคม";
|
|
case 8:
|
|
return "สิงหาคม";
|
|
case 9:
|
|
return "กันยายน";
|
|
case 10:
|
|
return "ตุลาคม";
|
|
case 11:
|
|
return "พฤศจิกายน";
|
|
case 12:
|
|
return "ธันวาคม";
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static ToThaiYear(value: number) {
|
|
if (value < 2400) return value + 543;
|
|
else return value;
|
|
}
|
|
|
|
public static ToCeYear(value: number) {
|
|
if (value >= 2400) return value - 543;
|
|
else return value;
|
|
}
|
|
|
|
public static ToThaiNumber(value: string) {
|
|
let arabicNumbers = "0123456789";
|
|
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
|
|
let result = "";
|
|
for (let digit of value) {
|
|
let index = arabicNumbers.indexOf(digit);
|
|
if (index >= 0) {
|
|
result += thaiNumbers[index];
|
|
} else {
|
|
result += digit;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static ToThaiFullDate(value: Date) {
|
|
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
|
return (
|
|
"วันที่ " +
|
|
value.getDate() +
|
|
" เดือน " +
|
|
Extension.ToThaiMonth(value.getMonth() + 1) +
|
|
" พ.ศ. " +
|
|
yy
|
|
);
|
|
}
|
|
|
|
public static sumObjectValues(array: any, propertyName: any) {
|
|
let sum = 0;
|
|
for (let i = 0; i < array.length; i++) {
|
|
if (array[i][propertyName] !== undefined) {
|
|
sum += array[i][propertyName];
|
|
}
|
|
}
|
|
return sum;
|
|
}
|
|
}
|
|
|
|
export default Extension;
|