1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

[PM-11350] Use shared expiration year normalization util function (#10735)

* use shared expiration year normalization util function

* use shared exp year normalization in web and desktop client

* handle cases where input has leading zeroes

* add utils tests

* handle cases where input is all zeroes
This commit is contained in:
Jonathan Prusik
2024-09-03 15:12:36 -04:00
committed by GitHub
parent b27dc44298
commit 5f2eecd7be
8 changed files with 142 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ import { Jsonify } from "type-fest";
import { CardLinkedId as LinkedId } from "../../enums";
import { linkedFieldOption } from "../../linked-field-option.decorator";
import { normalizeExpiryYearFormat } from "../../utils";
import { ItemView } from "./item.view";
@@ -65,17 +66,16 @@ export class CardView extends ItemView {
}
get expiration(): string {
if (!this.expMonth && !this.expYear) {
const normalizedYear = normalizeExpiryYearFormat(this.expYear);
if (!this.expMonth && !normalizedYear) {
return null;
}
let exp = this.expMonth != null ? ("0" + this.expMonth).slice(-2) : "__";
exp += " / " + (this.expYear != null ? this.formatYear(this.expYear) : "____");
return exp;
}
exp += " / " + (normalizedYear || "____");
private formatYear(year: string): string {
return year.length === 2 ? "20" + year : year;
return exp;
}
static fromJSON(obj: Partial<Jsonify<CardView>>): CardView {