Browse Source

[add]

年齢表示の処理を追加
poohr 3 weeks ago
parent
commit
839484d45e

+ 1
- 1
src/app/pages/danka-detail/danka-detail.html View File

@@ -242,7 +242,7 @@
242 242
                       </div>
243 243
 
244 244
                       <div>
245
-                        -
245
+                        {{ getAge(family.birthDate)}}
246 246
                       </div>
247 247
 
248 248
                       <div>

+ 18
- 0
src/app/pages/danka-detail/danka-detail.ts View File

@@ -24,6 +24,7 @@ export class DankaDetail {
24 24
     private familyService: FamilyService,
25 25
     private route: ActivatedRoute,
26 26
   ) {
27
+    //遷移先のIDから該当の世帯と家族基本を取得
27 28
     const id = this.route.snapshot.params['id'];
28 29
     if (id) {
29 30
       this.danka = this.dankaService.getDankaById(id);
@@ -32,4 +33,21 @@ export class DankaDetail {
32 33
     console.log(this.danka);
33 34
     console.log(this.families);
34 35
   }
36
+
37
+  getAge(birthDate: string) {
38
+    if (birthDate === '') {
39
+      return '-';
40
+    }
41
+
42
+    const birth = new Date(birthDate);
43
+    const today: Date = new Date();
44
+    const thisYearBirthday = new Date(today.getFullYear(), birth.getMonth(), birth.getDate());
45
+
46
+    let age = today.getFullYear() - birth.getFullYear();
47
+
48
+    if (thisYearBirthday > today) {
49
+      age--;
50
+    }
51
+    return age.toString();
52
+  }
35 53
 }

+ 2
- 0
src/app/services/family-service.ts View File

@@ -34,6 +34,8 @@ export class FamilyService {
34 34
   getFamiliesByDankaId(dankaId: string): Family[] {
35 35
     return this.families.filter((family) => family.dankaId === dankaId);
36 36
   }
37
+
38
+
37 39
   // getFamilyById(id: string);
38 40
   // addFamily(family: Family);
39 41
   // updateFamily(family: Family);

Loading…
Cancel
Save