Browse Source

[add]

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

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

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

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

24
     private familyService: FamilyService,
24
     private familyService: FamilyService,
25
     private route: ActivatedRoute,
25
     private route: ActivatedRoute,
26
   ) {
26
   ) {
27
+    //遷移先のIDから該当の世帯と家族基本を取得
27
     const id = this.route.snapshot.params['id'];
28
     const id = this.route.snapshot.params['id'];
28
     if (id) {
29
     if (id) {
29
       this.danka = this.dankaService.getDankaById(id);
30
       this.danka = this.dankaService.getDankaById(id);
32
     console.log(this.danka);
33
     console.log(this.danka);
33
     console.log(this.families);
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
   getFamiliesByDankaId(dankaId: string): Family[] {
34
   getFamiliesByDankaId(dankaId: string): Family[] {
35
     return this.families.filter((family) => family.dankaId === dankaId);
35
     return this.families.filter((family) => family.dankaId === dankaId);
36
   }
36
   }
37
+
38
+
37
   // getFamilyById(id: string);
39
   // getFamilyById(id: string);
38
   // addFamily(family: Family);
40
   // addFamily(family: Family);
39
   // updateFamily(family: Family);
41
   // updateFamily(family: Family);

Loading…
Cancel
Save