MCPcopy Create free account
hub / github.com/codemix/graph / fromMap

Method fromMap

packages/graph/src/TemporalTypes.ts:1156–1204  ·  view source on GitHub ↗

* Create a DurationValue from a map of components.

(map: Record<string, unknown>)

Source from the content-addressed store, hash-verified

1154 * Create a DurationValue from a map of components.
1155 */
1156 public static fromMap(map: Record<string, unknown>): DurationValue | null {
1157 let months = 0;
1158 let days = 0;
1159 let seconds = 0;
1160 let nanoseconds = 0;
1161
1162 // Handle years
1163 if (typeof map.years === "number") {
1164 months += map.years * 12;
1165 }
1166 // Handle months
1167 if (typeof map.months === "number") {
1168 months += map.months;
1169 }
1170 // Handle weeks
1171 if (typeof map.weeks === "number") {
1172 days += map.weeks * 7;
1173 }
1174 // Handle days
1175 if (typeof map.days === "number") {
1176 days += map.days;
1177 }
1178 // Handle hours
1179 if (typeof map.hours === "number") {
1180 seconds += map.hours * 3600;
1181 }
1182 // Handle minutes
1183 if (typeof map.minutes === "number") {
1184 seconds += map.minutes * 60;
1185 }
1186 // Handle seconds
1187 if (typeof map.seconds === "number") {
1188 seconds += map.seconds;
1189 }
1190 // Handle milliseconds
1191 if (typeof map.milliseconds === "number") {
1192 nanoseconds += map.milliseconds * 1_000_000;
1193 }
1194 // Handle microseconds
1195 if (typeof map.microseconds === "number") {
1196 nanoseconds += map.microseconds * 1_000;
1197 }
1198 // Handle nanoseconds
1199 if (typeof map.nanoseconds === "number") {
1200 nanoseconds += map.nanoseconds;
1201 }
1202
1203 return new DurationValue(months, days, seconds, nanoseconds);
1204 }
1205
1206 // Component accessors
1207 public get months(): number {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected