npm.io
0.0.3 • Published 6 years ago

ngx-timestamp-date

Licence
Version
0.0.3
Deps
1
Size
67 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

NgxTimestampDate

NgxTimestampDate is a simple @angular/fire tool provided by Anchor Solutions to convert timestamps in retrieved documents from firestore database back to JS Date object. It recursively parse the object document presented to located timestamp values and then convert them to JS Date normally.

Installation

Install ngx-timestamp-date via npm by running the following command:

npm install ngx-timestamp-date --save

Usage

Register the NgxTimestampDateModule in your app module (or any other module you want to use it).

import { NgxTimestampDateModule } from 'ngx-timestamp-date';

@NgModule({
 declarations: [],
 imports: [
   ...,
   NgxTimestampDateModule
 ],
 providers: [],
 bootstrap: []
})
export class AppModule {}
Use NgxTimestampDateService service from anywhere in your app like below:
@Injectable({
  providedIn: 'root'
})
export class MyService {
  constructor(private timestampService: NgxTimestampDateService) {
      // converts all timestamp in doc to js date
      const doc = {
          a: {},
          b: {
              c: [
                  d: <Timestamp>
              ],
              e: <Timestamp>
          }
      };

      const updated = this.timestampService.parseTimestampToDate(doc);

      console.log(doc, updated);
  }
}
Methods
Method Name Params Return type Description
timestampToDate Timestamp Date Converts timestamp object to date object
dateToTimestamp Date Timestamp Converts JS date object to timestamp
parseTimestampToDate Recursively iterates through properties of a JS object and convert all occurences of timestamp to normal JS Date
Further Reading

Have a look at other packages by Anchor Solutions:

Keywords