MCPcopy Create free account
hub / github.com/NativeScript/firebase / Timestamp

Class Timestamp

packages/firebase-firestore/index.android.ts:1187–1274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1185}
1186
1187export class Timestamp implements ITimestamp {
1188 _native: com.google.firebase.Timestamp;
1189
1190 constructor(seconds: number, nanoseconds: number, native = false) {
1191 if (!native) {
1192 this._native = new com.google.firebase.Timestamp(seconds, nanoseconds);
1193 }
1194 }
1195
1196 static fromNative(timestamp: com.google.firebase.Timestamp) {
1197 if (timestamp instanceof com.google.firebase.Timestamp) {
1198 const ts = new Timestamp(0, 0, true);
1199 ts._native = timestamp;
1200 return ts;
1201 }
1202 return null;
1203 }
1204
1205 static _dateFormat: java.text.SimpleDateFormat;
1206
1207 static fromDate(date: Date) {
1208 if (date instanceof Date) {
1209 const ts = new Timestamp(0, 0, true);
1210
1211 if (!this._dateFormat) {
1212 const dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
1213 const tz = java.util.TimeZone.getTimeZone('UTC');
1214 dateFormat.setTimeZone(tz);
1215 this._dateFormat = dateFormat;
1216 }
1217
1218 ts._native = new com.google.firebase.Timestamp(this._dateFormat.parse(date.toISOString()));
1219 return ts;
1220 }
1221 return null;
1222 }
1223
1224 static fromMillis(milliseconds: number) {
1225 const ts = new Timestamp(0, 0, true);
1226 ts._native = new com.google.firebase.Timestamp(milliseconds / 1000, 0);
1227 return ts;
1228 }
1229
1230 static now() {
1231 const ts = new Timestamp(0, 0, true);
1232 ts._native = com.google.firebase.Timestamp.now();
1233 return ts;
1234 }
1235
1236 isEqual(ts: Timestamp): boolean {
1237 return this.native.compareTo(ts.native) === 0;
1238 }
1239
1240 toDate() {
1241 return new Date(this._native.toDate().getTime());
1242 }
1243
1244 toMillis() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…