| 1058 | } |
| 1059 | |
| 1060 | export class Timestamp implements ITimestamp { |
| 1061 | _native: FIRTimestamp; |
| 1062 | |
| 1063 | constructor(seconds: number, nanoseconds: number, native = false) { |
| 1064 | if (!native) { |
| 1065 | this._native = FIRTimestamp.timestampWithSecondsNanoseconds(seconds, nanoseconds); |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | static fromNative(timestamp: FIRTimestamp) { |
| 1070 | if (timestamp instanceof FIRTimestamp) { |
| 1071 | const ts = new Timestamp(0, 0, true); |
| 1072 | ts._native = timestamp; |
| 1073 | return ts; |
| 1074 | } |
| 1075 | return null; |
| 1076 | } |
| 1077 | |
| 1078 | static fromDate(date: Date) { |
| 1079 | if (date instanceof Date) { |
| 1080 | const ts = new Timestamp(0, 0, true); |
| 1081 | ts._native = FIRTimestamp.timestampWithDate(date); |
| 1082 | return ts; |
| 1083 | } |
| 1084 | return null; |
| 1085 | } |
| 1086 | |
| 1087 | static fromMillis(milliseconds: number) { |
| 1088 | const ts = new Timestamp(0, 0, true); |
| 1089 | ts._native = FIRTimestamp.timestampWithSecondsNanoseconds(milliseconds / 1000, 0); |
| 1090 | return ts; |
| 1091 | } |
| 1092 | |
| 1093 | static now() { |
| 1094 | const ts = new Timestamp(0, 0, true); |
| 1095 | ts._native = FIRTimestamp.timestamp(); |
| 1096 | return ts; |
| 1097 | } |
| 1098 | |
| 1099 | get nanoseconds(): number { |
| 1100 | return this.native.nanoseconds; |
| 1101 | } |
| 1102 | |
| 1103 | get seconds(): number { |
| 1104 | return this.native.seconds; |
| 1105 | } |
| 1106 | |
| 1107 | isEqual(ts: Timestamp): boolean { |
| 1108 | return this.native.compare(ts.native) === NSComparisonResult.OrderedSame; |
| 1109 | } |
| 1110 | |
| 1111 | toDate() { |
| 1112 | return this.native.dateValue(); |
| 1113 | } |
| 1114 | |
| 1115 | toMillis() { |
| 1116 | return this.native.seconds * 1000; |
| 1117 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…