(year?: number | CalendarDate, month?: number | string, date?: number, calendarType?: string)
| 6 | _oUDate!: UI5Date | Date | UniversalDate; |
| 7 | |
| 8 | constructor(year?: number | CalendarDate, month?: number | string, date?: number, calendarType?: string) { // eslint-disable-line |
| 9 | let aArgs = arguments, // eslint-disable-line |
| 10 | oJSDate: UI5Date | Date, |
| 11 | oNow: UI5Date | Date, |
| 12 | sCalendarType!: CalendarType; |
| 13 | |
| 14 | switch (aArgs.length) { |
| 15 | case 0: // defaults to the current date |
| 16 | oNow = UI5Date.getInstance(); |
| 17 | return (this.constructor(oNow.getFullYear(), oNow.getMonth(), oNow.getDate()) as CalendarDate); |
| 18 | |
| 19 | case 1: // CalendarDate |
| 20 | case 2: // CalendarDate, sCalendarType |
| 21 | if (!(aArgs[0] instanceof CalendarDate)) { |
| 22 | throw new Error("Invalid arguments: the first argument must be of type CalendarDate."); |
| 23 | } |
| 24 | sCalendarType = aArgs[1] ? aArgs[1] : (aArgs[0]._oUDate as UniversalDate).sCalendarType; |
| 25 | // Use source.valueOf() (returns the same point of time regardless calendar type) instead of |
| 26 | // source's getters to avoid non-gregorian Year, Month and Date may be used to construct a Gregorian date |
| 27 | oJSDate = UI5Date.getInstance(aArgs[0].valueOf()); |
| 28 | |
| 29 | // Make this date really local. Now getters are safe. |
| 30 | oJSDate.setFullYear(oJSDate.getUTCFullYear(), oJSDate.getUTCMonth(), oJSDate.getUTCDate()); |
| 31 | oJSDate.setHours(oJSDate.getUTCHours(), oJSDate.getUTCMinutes(), oJSDate.getUTCSeconds(), oJSDate.getUTCMilliseconds()); |
| 32 | |
| 33 | this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType); |
| 34 | break; |
| 35 | |
| 36 | case 3: // year, month, date |
| 37 | case 4: // year, month, date, sCalendarType |
| 38 | checkNumericLike(aArgs[0] as number, `Invalid year: ${aArgs[0] as number}`); |
| 39 | checkNumericLike(aArgs[1] as number, `Invalid month: ${aArgs[1] as number}`); |
| 40 | checkNumericLike(aArgs[2] as number, `Invalid date: ${aArgs[2] as number}`); |
| 41 | |
| 42 | oJSDate = UI5Date.getInstance(0, 0, 1); |
| 43 | oJSDate.setFullYear(aArgs[0] as number, aArgs[1] as number, aArgs[2] as number); // 2 digits year is not supported. If so, it is considered as full year as well. |
| 44 | |
| 45 | if (aArgs[3]) { |
| 46 | sCalendarType = aArgs[3]; |
| 47 | } |
| 48 | this._oUDate = createUniversalUTCDate(oJSDate, sCalendarType); |
| 49 | break; |
| 50 | |
| 51 | default: |
| 52 | throw new Error(`${"Invalid arguments. Accepted arguments are: 1) oCalendarDate, (optional)calendarType" |
| 53 | + "or 2) year, month, date, (optional) calendarType"}${aArgs as unknown as string}`); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | getYear() { |
| 58 | return this._oUDate.getUTCFullYear(); |
nothing calls this directly
no test coverage detected