MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fx_Date_aux

Function fx_Date_aux

xs/sources/xsDate.c:155–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155void fx_Date_aux(txMachine* the, txFlag secure)
156{
157 txInteger c = mxArgc;
158 txDateTime dt;
159 txSlot* instance;
160 if (!mxHasTarget) {
161 char buffer[256];
162 txString p = buffer;
163 txDateTime dt;
164 if (secure)
165 mxTypeError("secure mode");
166 mxResult->value.number = fxDateNow();
167 mxResult->kind = XS_NUMBER_KIND;
168 fxDateSplit(mxResult->value.number, 0, &dt);
169 p = fxDatePrintDay(p, dt.day);
170 *p++ = ' ';
171 p = fxDatePrintDate(p, (txInteger)dt.year, (txInteger)dt.month, (txInteger)dt.date);
172 *p++ = ' ';
173 p = fxDatePrintTime(p, (txInteger)dt.hours, (txInteger)dt.minutes, (txInteger)dt.seconds);
174 *p++ = ' ';
175 p = fxDatePrintTimezone(p, (txInteger)dt.offset);
176 *p = 0;
177 fxCopyStringC(the, mxResult, buffer);
178 return;
179 }
180 mxPushSlot(mxTarget);
181 fxGetPrototypeFromConstructor(the, &mxDatePrototype);
182 instance = fxNewDateInstance(the);
183 mxPullSlot(mxResult);
184 if (c > 1) {
185 dt.year = fxDateFullYear(the, mxArgv(0));
186 dt.month = fxToNumber(the, mxArgv(1));
187 dt.date = (c > 2) ? fxToNumber(the, mxArgv(2)) : 1;
188 dt.hours = (c > 3) ? fxToNumber(the, mxArgv(3)) : 0;
189 dt.minutes = (c > 4) ? fxToNumber(the, mxArgv(4)) : 0;
190 dt.seconds = (c > 5) ?fxToNumber(the, mxArgv(5)) : 0;
191 dt.milliseconds = (c > 6) ? fxToNumber(the, mxArgv(6)) : 0;
192 instance->next->value.number = fxDateMerge(&dt, 0);
193 return;
194 }
195 if (c > 0) {
196 txSlot* slot = mxArgv(0);
197 if (slot->kind == XS_REFERENCE_KIND) {
198 txSlot* date = slot->value.reference;
199 if ((date->next) && (date->next->kind == XS_DATE_KIND)) {
200 instance->next->value.number = date->next->value.number;
201 return;
202 }
203 }
204 fxToPrimitive(the, slot, XS_NO_HINT);
205 if ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) {
206 mxPushSlot(mxFunction);
207 mxDub();
208 mxGetID(mxID(_parse));
209 mxCall();
210 mxPushSlot(slot);
211 mxRunCount(1);
212 instance->next->value.number = the->stack->value.number;

Callers 2

fx_DateFunction · 0.85
fx_Date_secureFunction · 0.85

Calls 14

fxDateNowFunction · 0.85
fxDateSplitFunction · 0.85
fxDatePrintDayFunction · 0.85
fxDatePrintDateFunction · 0.85
fxDatePrintTimeFunction · 0.85
fxDatePrintTimezoneFunction · 0.85
fxCopyStringCFunction · 0.85
fxNewDateInstanceFunction · 0.85
fxDateFullYearFunction · 0.85
fxToNumberFunction · 0.85
fxDateMergeFunction · 0.85

Tested by

no test coverage detected