0.0.3 • Published 4 years ago

ngx-timestamp-date v0.0.3

Weekly downloads
12
License
-
Repository
-
Last release
4 years ago

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 NameParamsReturn typeDescription
timestampToDateTimestampDateConverts timestamp object to date object
dateToTimestampDateTimestampConverts JS date object to timestamp
parseTimestampToDateRecursively 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: