@shisyamo4131/air-guard-v2-schemas 2.3.7-dev.21 → 2.3.7-dev.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Employee.js +31 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shisyamo4131/air-guard-v2-schemas",
3
- "version": "2.3.7-dev.21",
3
+ "version": "2.3.7-dev.22",
4
4
  "description": "Schemas for AirGuard V2",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/Employee.js CHANGED
@@ -154,30 +154,50 @@ export default class Employee extends FireModel {
154
154
 
155
155
  /**
156
156
  * 生年月日から年齢を計算します。
157
- * @returns {number|null} 年齢。dateOfBirthが設定されていない場合はnull。
157
+ * @returns {{years: number, months: number}|null} 年齢(年数と月数)。dateOfBirthが設定されていない場合はnull。
158
158
  */
159
159
  get age() {
160
160
  if (!this.dateOfBirth) return null;
161
161
  const today = new Date();
162
- let age = today.getUTCFullYear() - this.dateOfBirth.getUTCFullYear();
163
- const m = today.getUTCMonth() - this.dateOfBirth.getUTCMonth();
164
- const d = today.getUTCDate() - this.dateOfBirth.getUTCDate();
165
- if (m < 0 || (m === 0 && d < 0)) age--;
166
- return age;
162
+
163
+ let years = today.getUTCFullYear() - this.dateOfBirth.getUTCFullYear();
164
+ let months = today.getUTCMonth() - this.dateOfBirth.getUTCMonth();
165
+ const days = today.getUTCDate() - this.dateOfBirth.getUTCDate();
166
+
167
+ if (days < 0) {
168
+ months--;
169
+ }
170
+
171
+ if (months < 0) {
172
+ years--;
173
+ months += 12;
174
+ }
175
+
176
+ return { years, months };
167
177
  }
168
178
 
169
179
  /**
170
180
  * 入社日からの勤続年数を計算します。
171
- * @returns {number|null} 勤続年数。dateOfHireが設定されていない場合はnull。
181
+ * @returns {{years: number, months: number}|null} 勤続年数(年数と月数)。dateOfHireが設定されていない場合はnull。
172
182
  */
173
183
  get yearsOfService() {
174
184
  if (!this.dateOfHire) return null;
175
185
  const today = new Date();
186
+
176
187
  let years = today.getUTCFullYear() - this.dateOfHire.getUTCFullYear();
177
- const m = today.getUTCMonth() - this.dateOfHire.getUTCMonth();
178
- const d = today.getUTCDate() - this.dateOfHire.getUTCDate();
179
- if (m < 0 || (m === 0 && d < 0)) years--;
180
- return years;
188
+ let months = today.getUTCMonth() - this.dateOfHire.getUTCMonth();
189
+ const days = today.getUTCDate() - this.dateOfHire.getUTCDate();
190
+
191
+ if (days < 0) {
192
+ months--;
193
+ }
194
+
195
+ if (months < 0) {
196
+ years--;
197
+ months += 12;
198
+ }
199
+
200
+ return { years, months };
181
201
  }
182
202
 
183
203
  /**