Convert YearMonth to text

This commit is contained in:
Artur 2024-11-04 10:07:37 +01:00
parent 1509538afb
commit e75a8ee2fb
2 changed files with 19 additions and 9 deletions

View File

@ -74,9 +74,12 @@ interface FormValues {
this.addChangeValue();
const row = this.lifeFormArray.controls[ i -1 ] as FormGroup;
row.get( 'initialValueAsset' )?.setValue(asset.life[i].initial);
// row.get( 'year_month' )?.setValue( asset.life[i].when.toFormValue());
const row : FormGroup = this.lifeFormArray.controls[ i - 1 ];
const lifeChange : AssetLifeChange = asset.life[i];
row.get( 'initialValueAsset' )?.setValue( lifeChange.initial);
const ym : YearMonth = lifeChange.when;
//const when_txt = ym.toFormValue();
row.get( 'year_month' )?.setValue( lifeChange.when.year +'-' + lifeChange.when.month );
}

View File

@ -6,14 +6,21 @@ export enum TypeDepreciation{
export class YearMonth{
readonly year : number ;
readonly month : number ;
constructor( year_month:string ){
const [ year, month ] = year_month.split( '-').map(Number);
this.year = year;
this.month =month;
constructor( year_month:string | YearMonth ){
if (typeof year_month === 'string') {
const [year, month] = year_month.split('-').map(Number);
this.year = year;
this.month = month;
} else {
this.year = year_month.year;
this.month = year_month.month;
}
}
toFormValue(){
return this.year + "-" + this.month;
toFormValue() {
return `${this.year}-${this.month.toString().padStart(2, '0')}`;
}
}