This Angular Module allows you to generate a expiry date.
This Angular Module allows you to generate a expiry date. Provide the expiry time length and the start date and it will add the expiry time to the provided date giving you expires in as epoch.
npm install expiresin
`Scaffolding
Import the module into your project under imports
`
imports: [
BrowserModule,
AppRoutingModule,
ExpiresInModule
],
`Use
In your component file, import the module in the constructor
`
private expiresIn: ExpiresIn
`Create a time span
Model: TimeSpan(seconds, minutes, hours, days, months, years)
All are optional.
`
const ts = new TimeSpan(0, 30, 2) //2.5 hours
`Then call any of the functions, like the example below
`
const ts = new TimeSpan(0, 30, 2)
this.expiresIn.getExpiryTime(ts)
`ExpiryDate will be based on NOW as default
You can provide a Date Object
`
const ts = new TimeSpan(0, 30, 2) //2.5 hours
const myDate = new Date(2022, 8, 12, 8, 0, 0, 0)
const exp = this.expiresIn.getExpiryTime(ts, myDate)
`Returns
`
{ expiresIn: 9000, expires: 1640569229 }
`Here is a sample of a component setup
`` constructor(
private expiresIn: ExpiresIn
) {}
ngOnInit() {
const ts = new TimeSpan(0, 30, 2)
const exp = this.expiresIn.getExpiryTime(ts)
console.log(exp)
}
}