UNPKG

@magic-xpa/utils

Version:

magic utils package

351 lines (350 loc) 38.6 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { PICInterface } from "./PICInterface"; import { UtilStrByteMode } from "./UtilStrByteMode"; import { NNumber } from "@magic-xpa/mscorelib"; /** @type {?} */ const MAX_GENGO = 5; /** @type {?} */ const IDX_UPPERCASE_ALPHA = 0; /** @type {?} */ const IDX_LOWERCASE_ALPHA = 1; /** @type {?} */ const IDX_KANJI = 2; /** @type {?} */ const IDX_YEAR = 0; /** @type {?} */ const IDX_MONTH = 1; /** @type {?} */ const IDX_DAY = 2; /** @type {?} */ const IDX_DOY = 3; export class UtilDateJpn { constructor() { this.MaxGengo = MAX_GENGO; } /** * @return {?} */ static getInstance() { if (UtilDateJpn._instance === null) { UtilDateJpn._instance = new UtilDateJpn(); } return UtilDateJpn._instance; } /** * @return {?} */ static getArrayDow() { return UtilDateJpn.JweekStr; } /** * @param {?} intIdx * @return {?} */ static getStrDow(intIdx) { /** @type {?} */ let flag = intIdx < 0 || 7 < intIdx; if (flag) { intIdx = 0; } return UtilDateJpn.JweekStr[intIdx]; } /** * @param {?} month * @return {?} */ static convertStrMonth(month) { /** @type {?} */ let flag = month < 0 || 12 < month; if (flag) { month = 0; } return UtilDateJpn.JmonthStr[month]; } /** * @param {?} intYear * @param {?} intDoy * @return {?} */ date_jpn_year_ofs(intYear, intDoy) { /** @type {?} */ let result; if (intYear < 1 || intDoy < 1) { result = 0; } else { /** @type {?} */ let num = this.MaxGengo - 1; while (intYear < UtilDateJpn.StartDayOfGengo[num][0]) { num = num - 1; } if (intYear === UtilDateJpn.StartDayOfGengo[num][0] && intDoy < UtilDateJpn.StartDayOfGengo[num][3]) { num = num - 1; } result = intYear - UtilDateJpn.StartDayOfGengo[num][0] + 1; } return result; } /** * @param {?} intYear * @param {?} intDoy * @param {?} isKanji * @return {?} */ date_jpn_yr_2_a(intYear, intDoy, isKanji) { /** @type {?} */ let num; if (intYear < 1 || intDoy < 1) { num = 0; } else { num = this.MaxGengo - 1; while (intYear < UtilDateJpn.StartDayOfGengo[num][0]) { num = num - 1; } if (intYear === UtilDateJpn.StartDayOfGengo[num][0] && intDoy < UtilDateJpn.StartDayOfGengo[num][3]) { num = num - 1; } } /** @type {?} */ let result; if (isKanji) { result = UtilDateJpn.GengoStr[num][2]; } else { result = UtilDateJpn.GengoStr[num][0]; } return result; } /** * @param {?} ucp_str * @param {?} s_len * @return {?} */ date_jpn_yr_4_a(ucp_str, s_len) { /** @type {?} */ let i = this.MaxGengo - 1; if (s_len > 0) { if (s_len > 1) { ucp_str = UtilStrByteMode.leftB(ucp_str, s_len); } while (i > 0) { if (s_len === 1) { if (ucp_str === UtilDateJpn.GengoStr[i][0] || ucp_str === UtilDateJpn.GengoStr[i][1]) { break; } } else { if (s_len > 1) { /** @type {?} */ let text = UtilStrByteMode.leftB(UtilDateJpn.GengoStr[i][2], s_len); if (ucp_str === text) { break; } } } i = i - 1; } } /** @type {?} */ let result; if (i > 0) { result = UtilDateJpn.StartDayOfGengo[i][0]; } else { /** @type {?} */ const text = ucp_str.substr(0, 1); if (text === " " || text === "?") { result = 1; } else { result = 0; } } return result; } /** * @param {?} strDate * @param {?} strPicture * @param {?} intStartPos * @return {?} */ static getEraNameStrInDate(strDate, strPicture, intStartPos) { /** @type {?} */ let result = null; /** @type {?} */ let intPicIdxOfs = 0; /** @type {?} */ let i = intStartPos; while (i + intPicIdxOfs < strPicture.length) { /** @type {?} */ let intLetters; if (strPicture.charCodeAt(i + intPicIdxOfs) === PICInterface.PIC_JY1) { intLetters = 1; } else { if (strPicture.charCodeAt(i + intPicIdxOfs) === PICInterface.PIC_JY2) { intLetters = 1; } else { if (strPicture.charCodeAt(i + intPicIdxOfs) === PICInterface.PIC_JY4) { intLetters = 2; } else { // If "strDate" contains DBCS, the position of "strPicture" has to skip next index. if (i < strDate.length) { if (!UtilStrByteMode.isHalfWidth(strDate[i]) && UtilStrByteMode.isHalfWidth(strPicture[i + intPicIdxOfs])) { intPicIdxOfs = intPicIdxOfs + 1; } } i = i + 1; continue; } } } result = strDate.substr(i, intLetters); break; // exit loop } return result; } /** * @param {?} strPicture * @param {?} intStartPos * @return {?} */ static getEraNameLenInPicture(strPicture, intStartPos) { /** @type {?} */ let intLetters = 0; for (let i = intStartPos; i < strPicture.length; i = i + 1) { if (strPicture.charCodeAt(i) === PICInterface.PIC_JY1) { intLetters = 1; } else { if (strPicture.charCodeAt(i) === PICInterface.PIC_JY2) { intLetters = 2; } else { if (strPicture.charCodeAt(i) === PICInterface.PIC_JY4) { intLetters = 4; } } } if (intLetters > 0) { break; } } return intLetters; } /** * @param {?} strDate * @param {?} strPicture * @return {?} */ getStartYearOfEra(strDate, strPicture) { /** @type {?} */ let eraNameStrInDate = UtilDateJpn.getEraNameStrInDate(strDate, strPicture, 0); /** @type {?} */ let result; if (eraNameStrInDate === null) { result = 0; } else { /** @type {?} */ let eraNameLenInPicture = UtilDateJpn.getEraNameLenInPicture(strPicture, 0); if (eraNameLenInPicture === 0) { result = 0; } else { /** @type {?} */ let intStartYearOfEra = this.date_jpn_yr_4_a(eraNameStrInDate, eraNameLenInPicture); result = intStartYearOfEra; } } return result; } /** * @param {?} strExtraGengo * @return {?} */ addExtraGengo(strExtraGengo) { /** @type {?} */ let array = strExtraGengo.split(';'); for (let i = 0; i <= array.length; i = i + 1) { if (array[i].length > 0) { /** @type {?} */ let array2 = array[i].split(','); if (array2.length === 2 && array2[0].length > 0 && array2[1].length > 0 && array2[2].length > 0) { /** @type {?} */ let array3 = array2[0].split('/'); if (array3.length === 2 && array3[0].length > 0 && array3[1].length > 0 && array3[2].length > 0) { UtilDateJpn.GengoStr[5 + i][0] = array2[2].substr(0, 1); // symbol name (upper case): A UtilDateJpn.GengoStr[5 + i][1] = array2[2].substr(1, 1); // symbol name (lower case): a UtilDateJpn.GengoStr[5 + i][2] = array2[2].substr(2); // gengo name: ABCD UtilDateJpn.StartDayOfGengo[5 + i][0] = NNumber.Parse(array3[0]); // start year: 2012 UtilDateJpn.StartDayOfGengo[5 + i][1] = NNumber.Parse(array3[1]); // start month: 4 UtilDateJpn.StartDayOfGengo[5 + i][2] = NNumber.Parse(array3[2]); // start day: 1 UtilDateJpn.StartDayOfGengo[5 + i][3] = NNumber.Parse(array2[1]); // days since January 1: 92 this.MaxGengo = this.MaxGengo + 1; } } } } } } UtilDateJpn._instance = null; UtilDateJpn.JweekStr = [ " ", "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日" ]; UtilDateJpn.JmonthStr = [ "", " 1月", " 2月", " 3月", " 4月", " 5月", " 6月", " 7月", " 8月", " 9月", "10月", "11月", "12月" ]; UtilDateJpn.GengoStr = [ [ "?", "?", "????" ], [ "M", "m", "明治" ], [ "T", "t", "大正" ], [ "S", "s", "昭和" ], [ "H", "h", "平成" ], [ "?", "?", "??" ], [ "?", "?", "??" ], [ "?", "?", "??" ] ]; UtilDateJpn.StartDayOfGengo = [ [ 1, 1, 1, 1 ], [ 1868, 9, 8, 252 ], [ 1912, 6, 30, 212 ], [ 1926, 12, 25, 359 ], [ 1989, 1, 8, 8 ], new Array(4), new Array(4), new Array(4) ]; if (false) { /** @type {?} */ UtilDateJpn._instance; /** @type {?} */ UtilDateJpn.JweekStr; /** @type {?} */ UtilDateJpn.JmonthStr; /** @type {?} */ UtilDateJpn.GengoStr; /** @type {?} */ UtilDateJpn.StartDayOfGengo; /** @type {?} */ UtilDateJpn.prototype.MaxGengo; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVXRpbERhdGVKcG4uanMiLCJzb3VyY2VSb290Ijoibmc6Ly9AbWFnaWMteHBhL3V0aWxzLyIsInNvdXJjZXMiOlsic3JjL1V0aWxEYXRlSnBuLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7QUFBQSxPQUFPLEVBQUMsWUFBWSxFQUFDLE1BQU0sZ0JBQWdCLENBQUM7QUFD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V0dXJucz4geWVhciAoQS5ELilcclxuICAvLy8gPC9yZXR1cm5zPlxyXG4gIHByaXZhdGUgZGF0ZV9qcG5feXJfNF9hKHVjcF9zdHI6IHN0cmluZywgc19sZW46IG51bWJlcik6IG51bWJlciB7XHJcbiAgICBsZXQgaTogbnVtYmVyID0gdGhpcy5NYXhHZW5nbyAtIDE7XHJcbiAgICBpZiAoc19sZW4gPiAwKSB7XHJcbiAgICAgIGlmIChzX2xlbiA+IDEpIHtcclxuICAgICAgICB1Y3Bfc3RyID0gVXRpbFN0ckJ5dGVNb2RlLmxlZnRCKHVjcF9zdHIsIHNfbGVuKTtcclxuICAgICAgfVxyXG4gICAgICB3aGlsZSAoaSA+IDApIHtcclxuICAgICAgICBpZiAoc19sZW4gPT09IDEpIHtcclxuICAgICAgICAgIGlmICh1Y3Bfc3RyID09PSBVdGlsRGF0ZUpwbi5HZW5nb1N0cltpXVswXSB8fCB1Y3Bfc3RyID09PSBVdGlsRGF0ZUpwbi5HZW5nb1N0cltpXVsxXSkge1xyXG4gICAgICAgICAgICBicmVhaztcclxuICAgICAgICAgIH1cclxuICAgICAgICB9XHJcbiAgICAgICAgZWxzZSB7XHJcbiAgICAgICAgICBpZiAoc19sZW4gPiAxKSB7XHJcbiAgICAgICAgICAgIGxldCB0ZXh0OiBzdHJpbmcgPSBVdGlsU3RyQnl0ZU1vZGUubGVmdEIoVXRpbERhdGVKcG4uR2VuZ29TdHJbaV1bMl0sIHNfbGVuKTtcclxuICAgICAgICAgICAgaWYgKHVjcF9zdHIgPT09IHRleHQpIHtcclxuICAgICAgICAgICAgICBicmVhaztcclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgfVxyXG4gICAgICAgIH1cclxuICAgICAgICBpID0gaSAtIDE7XHJcbiAgICAgIH1cclxuICAgIH1cclxuICAgIGxldCByZXN1bHQ6IG51bWJlcjtcclxuICAgIGlmIChpID4gMCkge1xyXG4gICAgICByZXN1bHQgPSBVdGlsRGF0ZUpwbi5TdGFydER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A9IDA7XHJcbiAgICBsZXQgaTogbnVtYmVyID0gaW50U3RhcnRQb3M7XHJcbiAgICB3aGlsZSAoaSArIGludFBpY0lkeE9mcyA8IHN0clBpY3R1cmUubGVuZ3RoKSB7XHJcbiAgICAgIGxldCBpbnRMZXR0ZXJzOiBudW1iZXI7XHJcbiAgICAgIGlmIChzdHJQaWN0dXJlLmNoYXJDb2RlQXQoaSArIGludFBpY0lkeE9mcykgPT09IFBJQ0ludGVyZmFjZS5QSUNfSlkxKSB7XHJcbiAgICAgICAgaW50TGV0dGVycyA9IDE7XHJcbiAgICAgIH1cclxuICAgICAgZWxzZSB7XHJcbiAgICAgICAgaWYgKHN0clBpY3R1cmUuY2hhckNvZGVBdChpICsgaW50UGljSWR4T2ZzKSA9PT0gUElDSW50ZXJmYWNlLlBJQ19KWTIpIHtcclxuICAgICAgICAgIGludExldHRlcnMgPSAxO1xyXG4gICAgICAgIH1cclxuICAgICAgICBlbHNlIHtcclxuICAgICAgICAgIGlmIChzdHJQaWN0dXJlLmNoYXJDb2RlQXQoaSArIGludFBpY0lkeE9mcykgPT09IFBJQ0ludGVyZmFjZS5QSUNfSlk0KSB7XHJcbiAgICAgICAgICAgIGludExldHRlcnMgPSAyO1xyXG4gICAgICAgICAgfSBlbHNlIHtcclxuICAgICAgICAgICAgLy8gSWYgXCJzdHJEYXRlXCIgY29udGFpbnMgREJDUywgdGhlIHBvc2l0aW9uIG9mIFwic3RyUGljdHVyZVwiIGhhcyB0byBza2lwIG5leHQgaW5kZXguXHJcbiAgICAgICAgICAgIGlmIChpIDwgc3RyRGF0ZS5sZW5ndGgpIHtcclxuICAgICAgICAgICAgICBpZiAoIVV0aWxTdHJCeXRlTW9kZS5pc0hhbGZXaWR0aChzdHJEYXRlW2ldKSAmJiBVdGlsU3RyQnl0ZU1vZGUuaXNIYWxmV2lkdGgoc3RyUGljdHVyZVtpICsgaW50UGljSWR4T2ZzXSkpIHtcclxuICAgICAgICAgICAgICAgIGludFBpY0lkeE9mc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