getRemainSubDuration method

Duration getRemainSubDuration(
  1. PurchaseDetails purchaseDetails
)

Implementation

Duration getRemainSubDuration(PurchaseDetails purchaseDetails) {
  DateTime currentTime = DateTime.now();
  DateTime purchaseDate = DateTime.fromMillisecondsSinceEpoch(
    int.parse(purchaseDetails.transactionDate ?? "0"),
  ).add(
    Duration(
      days: purchaseDetails.productID == "weekly_pack"
          ? 7
          : purchaseDetails.productID == "monthly_pack_1"
          ? 30
          : purchaseDetails.productID == "yearly_pack_2"
          ? 365
          : 0,
    ),
  );
  log(currentTime.toString());
  log(purchaseDate.toString());
  log(currentTime.difference(purchaseDate).toString());
  log(purchaseDate.difference(currentTime).toString());
  return purchaseDate.difference(currentTime);
}