@agoric/xsnap 0.14.3-u13.0 → 0.14.3-u16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/api.js +4 -2
- package/build.env +1 -1
- package/moddable/modules/data/base64/base64.js +28 -0
- package/moddable/modules/data/base64/manifest.json +11 -0
- package/moddable/modules/data/base64/modBase64.c +188 -0
- package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
- package/moddable/modules/data/crc/crc.c +205 -0
- package/moddable/modules/data/crc/crc.js +36 -0
- package/moddable/modules/data/crc/manifest.json +8 -0
- package/moddable/modules/data/hex/hex.js +28 -0
- package/moddable/modules/data/hex/manifest.json +11 -0
- package/moddable/modules/data/hex/modHex.c +139 -0
- package/moddable/modules/data/logical/logical.js +32 -0
- package/moddable/modules/data/logical/modLogical.c +98 -0
- package/moddable/modules/data/qrcode/manifest.json +9 -0
- package/moddable/modules/data/qrcode/qrcode.c +93 -0
- package/moddable/modules/data/qrcode/qrcode.js +23 -0
- package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
- package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
- package/moddable/modules/data/text/decoder/manifest.json +8 -0
- package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
- package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
- package/moddable/modules/data/text/encoder/manifest.json +8 -0
- package/moddable/modules/data/text/encoder/textencoder.c +232 -0
- package/moddable/modules/data/text/encoder/textencoder.js +24 -0
- package/moddable/modules/data/tinyint/tinyint.c +150 -0
- package/moddable/modules/data/tinyint/tinyint.js +53 -0
- package/moddable/modules/data/url/manifest.json +17 -0
- package/moddable/modules/data/url/url.c +1959 -0
- package/moddable/modules/data/url/url.js +210 -0
- package/moddable/modules/data/wavreader/manifest.json +8 -0
- package/moddable/modules/data/wavreader/wavreader.js +128 -0
- package/moddable/modules/data/zlib/deflate.c +161 -0
- package/moddable/modules/data/zlib/deflate.js +63 -0
- package/moddable/modules/data/zlib/inflate.c +145 -0
- package/moddable/modules/data/zlib/inflate.js +66 -0
- package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
- package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
- package/moddable/modules/data/zlib/miniz.c +4924 -0
- package/moddable/xs/includes/xs.d.ts +73 -0
- package/moddable/xs/includes/xs.h +1533 -0
- package/moddable/xs/includes/xsmc.h +206 -0
- package/moddable/xs/makefiles/lin/makefile +33 -0
- package/moddable/xs/makefiles/lin/xsc.mk +118 -0
- package/moddable/xs/makefiles/lin/xsid.mk +90 -0
- package/moddable/xs/makefiles/lin/xsl.mk +168 -0
- package/moddable/xs/makefiles/lin/xst.mk +201 -0
- package/moddable/xs/makefiles/mac/makefile +33 -0
- package/moddable/xs/makefiles/mac/xsc.mk +130 -0
- package/moddable/xs/makefiles/mac/xsid.mk +102 -0
- package/moddable/xs/makefiles/mac/xsl.mk +177 -0
- package/moddable/xs/makefiles/mac/xst.mk +203 -0
- package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
- package/moddable/xs/makefiles/win/build.bat +26 -0
- package/moddable/xs/makefiles/win/xsc.mak +142 -0
- package/moddable/xs/makefiles/win/xsid.mak +113 -0
- package/moddable/xs/makefiles/win/xsl.mak +186 -0
- package/moddable/xs/makefiles/win/xst.mak +195 -0
- package/moddable/xs/platforms/lin_xs.h +99 -0
- package/moddable/xs/platforms/mac_xs.h +97 -0
- package/moddable/xs/platforms/wasm_xs.h +79 -0
- package/moddable/xs/platforms/win_xs.h +104 -0
- package/moddable/xs/platforms/xsHost.h +63 -0
- package/moddable/xs/platforms/xsPlatform.h +618 -0
- package/moddable/xs/sources/xsAPI.c +2555 -0
- package/moddable/xs/sources/xsAll.c +294 -0
- package/moddable/xs/sources/xsAll.h +2741 -0
- package/moddable/xs/sources/xsArguments.c +222 -0
- package/moddable/xs/sources/xsArray.c +2657 -0
- package/moddable/xs/sources/xsAtomics.c +844 -0
- package/moddable/xs/sources/xsBigInt.c +1859 -0
- package/moddable/xs/sources/xsBoolean.c +109 -0
- package/moddable/xs/sources/xsCode.c +4493 -0
- package/moddable/xs/sources/xsCommon.c +1710 -0
- package/moddable/xs/sources/xsCommon.h +1142 -0
- package/moddable/xs/sources/xsDataView.c +2890 -0
- package/moddable/xs/sources/xsDate.c +1541 -0
- package/moddable/xs/sources/xsDebug.c +2710 -0
- package/moddable/xs/sources/xsDefaults.c +134 -0
- package/moddable/xs/sources/xsError.c +353 -0
- package/moddable/xs/sources/xsFunction.c +776 -0
- package/moddable/xs/sources/xsGenerator.c +865 -0
- package/moddable/xs/sources/xsGlobal.c +839 -0
- package/moddable/xs/sources/xsJSON.c +1091 -0
- package/moddable/xs/sources/xsLexical.c +1969 -0
- package/moddable/xs/sources/xsLockdown.c +933 -0
- package/moddable/xs/sources/xsMapSet.c +1649 -0
- package/moddable/xs/sources/xsMarshall.c +1020 -0
- package/moddable/xs/sources/xsMath.c +624 -0
- package/moddable/xs/sources/xsMemory.c +1941 -0
- package/moddable/xs/sources/xsModule.c +3101 -0
- package/moddable/xs/sources/xsNumber.c +560 -0
- package/moddable/xs/sources/xsObject.c +1102 -0
- package/moddable/xs/sources/xsPlatforms.c +480 -0
- package/moddable/xs/sources/xsProfile.c +577 -0
- package/moddable/xs/sources/xsPromise.c +1199 -0
- package/moddable/xs/sources/xsProperty.c +636 -0
- package/moddable/xs/sources/xsProxy.c +1014 -0
- package/moddable/xs/sources/xsRegExp.c +1168 -0
- package/moddable/xs/sources/xsRun.c +4889 -0
- package/moddable/xs/sources/xsScope.c +1293 -0
- package/moddable/xs/sources/xsScript.c +288 -0
- package/moddable/xs/sources/xsScript.h +1186 -0
- package/moddable/xs/sources/xsSnapshot.c +2161 -0
- package/moddable/xs/sources/xsSnapshot.h +51 -0
- package/moddable/xs/sources/xsSourceMap.c +218 -0
- package/moddable/xs/sources/xsString.c +3332 -0
- package/moddable/xs/sources/xsSymbol.c +503 -0
- package/moddable/xs/sources/xsSyntaxical.c +4193 -0
- package/moddable/xs/sources/xsTree.c +1893 -0
- package/moddable/xs/sources/xsType.c +1488 -0
- package/moddable/xs/sources/xsdtoa.c +6672 -0
- package/moddable/xs/sources/xsmc.c +340 -0
- package/moddable/xs/sources/xsre.c +7578 -0
- package/package.json +39 -22
- package/scripts/get_xsnap_version.sh +14 -0
- package/scripts/test-package.sh +21 -0
- package/src/avaAssertXS.js +6 -2
- package/src/avaHandler.cjs +2 -5
- package/src/avaXS.js +7 -8
- package/src/build.js +161 -28
- package/src/replay.js +0 -3
- package/src/xsnap.js +105 -91
- package/src/xsrepl.js +2 -3
- package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
- package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
- package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
- package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
- package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
- package/xsnap-native/xsnap/sources/xsnap.c +717 -0
- package/xsnap-native/xsnap/sources/xsnap.h +142 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
- package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
- package/CHANGELOG.md +0 -646
|
@@ -0,0 +1,1541 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-2017 Moddable Tech, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of the Moddable SDK Runtime.
|
|
5
|
+
*
|
|
6
|
+
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* The Moddable SDK Runtime is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU Lesser General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
* along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*
|
|
19
|
+
* This file incorporates work covered by the following copyright and
|
|
20
|
+
* permission notice:
|
|
21
|
+
*
|
|
22
|
+
* Copyright (C) 2010-2016 Marvell International Ltd.
|
|
23
|
+
* Copyright (C) 2002-2010 Kinoma, Inc.
|
|
24
|
+
*
|
|
25
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
26
|
+
* you may not use this file except in compliance with the License.
|
|
27
|
+
* You may obtain a copy of the License at
|
|
28
|
+
*
|
|
29
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
30
|
+
*
|
|
31
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
32
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
33
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
34
|
+
* See the License for the specific language governing permissions and
|
|
35
|
+
* limitations under the License.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
#include "xsAll.h"
|
|
39
|
+
|
|
40
|
+
typedef struct sxDateTime {
|
|
41
|
+
txNumber year;
|
|
42
|
+
txNumber month;
|
|
43
|
+
txNumber date;
|
|
44
|
+
txNumber hours;
|
|
45
|
+
txNumber minutes;
|
|
46
|
+
txNumber seconds;
|
|
47
|
+
txNumber milliseconds;
|
|
48
|
+
txInteger day;
|
|
49
|
+
txInteger offset;
|
|
50
|
+
} txDateTime;
|
|
51
|
+
|
|
52
|
+
static txSlot* fxNewDateInstance(txMachine* the);
|
|
53
|
+
|
|
54
|
+
static void fx_Date_aux(txMachine* the, txFlag secure);
|
|
55
|
+
static txInteger fx_Date_parse_number(txByte* theCharacter, txString* theString);
|
|
56
|
+
static txInteger fx_Date_parse_fraction(txByte* theCharacter, txString* theString);
|
|
57
|
+
static txBoolean fx_Date_prototype_get_aux(txMachine* the, txDateTime* td, txBoolean utc, txSlot* slot);
|
|
58
|
+
static void fx_Date_prototype_set_aux(txMachine* the, txDateTime* td, txBoolean utc, txSlot* slot);
|
|
59
|
+
|
|
60
|
+
static txSlot* fxDateCheck(txMachine* the);
|
|
61
|
+
static txNumber fxDateClip(txNumber value);
|
|
62
|
+
static txNumber fxDateFullYear(txMachine* the, txSlot* slot);
|
|
63
|
+
static txNumber fxDateMerge(txDateTime* dt, txBoolean utc);
|
|
64
|
+
static txString fxDatePrint2Digits(txString p, txInteger value);
|
|
65
|
+
static txString fxDatePrint3Digits(txString p, txInteger value);
|
|
66
|
+
static txString fxDatePrint4Digits(txString p, txInteger value);
|
|
67
|
+
static txString fxDatePrintDate(txString p, txInteger year, txInteger month, txInteger date);
|
|
68
|
+
static txString fxDatePrintDateUTC(txString p, txInteger year, txInteger month, txInteger date);
|
|
69
|
+
static txString fxDatePrintDay(txString p, txInteger day);
|
|
70
|
+
static txString fxDatePrintTime(txString p, txInteger hours, txInteger minutes, txInteger seconds);
|
|
71
|
+
static txString fxDatePrintTimezone(txString p, txInteger offset);
|
|
72
|
+
static txString fxDatePrintYear(txString p, txInteger value);
|
|
73
|
+
static txInteger fxDateSimilarYear(txInteger year);
|
|
74
|
+
static void fxDateSplit(txNumber value, txBoolean utc, txDateTime* dt);
|
|
75
|
+
|
|
76
|
+
void fxBuildDate(txMachine* the)
|
|
77
|
+
{
|
|
78
|
+
txSlot* slot;
|
|
79
|
+
mxPush(mxObjectPrototype);
|
|
80
|
+
slot = fxLastProperty(the, fxNewObjectInstance(the));
|
|
81
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getMilliseconds), 0, mxID(_getMilliseconds), XS_DONT_ENUM_FLAG);
|
|
82
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getSeconds), 0, mxID(_getSeconds), XS_DONT_ENUM_FLAG);
|
|
83
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getMinutes), 0, mxID(_getMinutes), XS_DONT_ENUM_FLAG);
|
|
84
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getHours), 0, mxID(_getHours), XS_DONT_ENUM_FLAG);
|
|
85
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getDay), 0, mxID(_getDay), XS_DONT_ENUM_FLAG);
|
|
86
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getDate), 0, mxID(_getDate), XS_DONT_ENUM_FLAG);
|
|
87
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getMonth), 0, mxID(_getMonth), XS_DONT_ENUM_FLAG);
|
|
88
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getYear), 0, mxID(_getYear), XS_DONT_ENUM_FLAG);
|
|
89
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getFullYear), 0, mxID(_getFullYear), XS_DONT_ENUM_FLAG);
|
|
90
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCMilliseconds), 0, mxID(_getUTCMilliseconds), XS_DONT_ENUM_FLAG);
|
|
91
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCSeconds), 0, mxID(_getUTCSeconds), XS_DONT_ENUM_FLAG);
|
|
92
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCMinutes), 0, mxID(_getUTCMinutes), XS_DONT_ENUM_FLAG);
|
|
93
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCHours), 0, mxID(_getUTCHours), XS_DONT_ENUM_FLAG);
|
|
94
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCDay), 0, mxID(_getUTCDay), XS_DONT_ENUM_FLAG);
|
|
95
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCDate), 0, mxID(_getUTCDate), XS_DONT_ENUM_FLAG);
|
|
96
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCMonth), 0, mxID(_getUTCMonth), XS_DONT_ENUM_FLAG);
|
|
97
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getUTCFullYear), 0, mxID(_getUTCFullYear), XS_DONT_ENUM_FLAG);
|
|
98
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_valueOf), 0, mxID(_getTime), XS_DONT_ENUM_FLAG);
|
|
99
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_getTimezoneOffset), 0, mxID(_getTimezoneOffset), XS_DONT_ENUM_FLAG);
|
|
100
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setDate), 1, mxID(_setDate), XS_DONT_ENUM_FLAG);
|
|
101
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setFullYear), 3, mxID(_setFullYear), XS_DONT_ENUM_FLAG);
|
|
102
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setHours), 4, mxID(_setHours), XS_DONT_ENUM_FLAG);
|
|
103
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setMilliseconds), 1, mxID(_setMilliseconds), XS_DONT_ENUM_FLAG);
|
|
104
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setMinutes), 3, mxID(_setMinutes), XS_DONT_ENUM_FLAG);
|
|
105
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setMonth), 2, mxID(_setMonth), XS_DONT_ENUM_FLAG);
|
|
106
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setSeconds), 2, mxID(_setSeconds), XS_DONT_ENUM_FLAG);
|
|
107
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setTime), 1, mxID(_setTime), XS_DONT_ENUM_FLAG);
|
|
108
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setYear), 1, mxID(_setYear), XS_DONT_ENUM_FLAG);
|
|
109
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setUTCDate), 1, mxID(_setUTCDate), XS_DONT_ENUM_FLAG);
|
|
110
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setUTCFullYear), 3, mxID(_setUTCFullYear), XS_DONT_ENUM_FLAG);
|
|
111
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setUTCHours), 4, mxID(_setUTCHours), XS_DONT_ENUM_FLAG);
|
|
112
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setUTCMilliseconds), 1, mxID(_setUTCMilliseconds), XS_DONT_ENUM_FLAG);
|
|
113
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setUTCMinutes), 3, mxID(_setUTCMinutes), XS_DONT_ENUM_FLAG);
|
|
114
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setUTCMonth), 2, mxID(_setUTCMonth), XS_DONT_ENUM_FLAG);
|
|
115
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_setUTCSeconds), 2, mxID(_setUTCSeconds), XS_DONT_ENUM_FLAG);
|
|
116
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toDateString), 0, mxID(_toDateString), XS_DONT_ENUM_FLAG);
|
|
117
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toISOString), 0, mxID(_toISOString), XS_DONT_ENUM_FLAG);
|
|
118
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toJSON), 1, mxID(_toJSON), XS_DONT_ENUM_FLAG);
|
|
119
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toDateString), 0, mxID(_toLocaleDateString), XS_DONT_ENUM_FLAG);
|
|
120
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toString), 0, mxID(_toLocaleString), XS_DONT_ENUM_FLAG);
|
|
121
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toTimeString), 0, mxID(_toLocaleTimeString), XS_DONT_ENUM_FLAG);
|
|
122
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toString), 0, mxID(_toString), XS_DONT_ENUM_FLAG);
|
|
123
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toTimeString), 0, mxID(_toTimeString), XS_DONT_ENUM_FLAG);
|
|
124
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toUTCString), 0, mxID(_toUTCString), XS_DONT_ENUM_FLAG);
|
|
125
|
+
slot = fxNextSlotProperty(the, slot, slot, mxID(_toGMTString), XS_DONT_ENUM_FLAG);
|
|
126
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_valueOf), 0, mxID(_valueOf), XS_DONT_ENUM_FLAG);
|
|
127
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_prototype_toPrimitive), 1, mxID(_Symbol_toPrimitive), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
|
|
128
|
+
mxDatePrototype = *the->stack;
|
|
129
|
+
slot = fxBuildHostConstructor(the, mxCallback(fx_Date), 7, mxID(_Date));
|
|
130
|
+
mxDateConstructor = *the->stack;
|
|
131
|
+
slot = fxLastProperty(the, slot);
|
|
132
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_now), 0, mxID(_now), XS_DONT_ENUM_FLAG);
|
|
133
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_parse), 1, mxID(_parse), XS_DONT_ENUM_FLAG);
|
|
134
|
+
slot = fxNextHostFunctionProperty(the, slot, mxCallback(fx_Date_UTC), 7, mxID(_UTC), XS_DONT_ENUM_FLAG);
|
|
135
|
+
mxPop();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
txSlot* fxNewDateInstance(txMachine* the)
|
|
139
|
+
{
|
|
140
|
+
txSlot* instance;
|
|
141
|
+
txSlot* property;
|
|
142
|
+
instance = fxNewObjectInstance(the);
|
|
143
|
+
property = fxNextNumberProperty(the, instance, 0, XS_NO_ID, XS_INTERNAL_FLAG);
|
|
144
|
+
property->kind = XS_DATE_KIND;
|
|
145
|
+
property->value.number = C_NAN;
|
|
146
|
+
return instance;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void fx_Date(txMachine* the)
|
|
150
|
+
{
|
|
151
|
+
fx_Date_aux(the, 0);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
void fx_Date_aux(txMachine* the, txFlag secure)
|
|
155
|
+
{
|
|
156
|
+
txInteger c = mxArgc;
|
|
157
|
+
txDateTime dt;
|
|
158
|
+
txSlot* instance;
|
|
159
|
+
if (mxIsUndefined(mxTarget)) {
|
|
160
|
+
char buffer[256];
|
|
161
|
+
txString p = buffer;
|
|
162
|
+
txDateTime dt;
|
|
163
|
+
if (secure)
|
|
164
|
+
mxTypeError("secure mode");
|
|
165
|
+
mxResult->value.number = fxDateNow();
|
|
166
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
167
|
+
fxDateSplit(mxResult->value.number, 0, &dt);
|
|
168
|
+
p = fxDatePrintDay(p, dt.day);
|
|
169
|
+
*p++ = ' ';
|
|
170
|
+
p = fxDatePrintDate(p, (txInteger)dt.year, (txInteger)dt.month, (txInteger)dt.date);
|
|
171
|
+
*p++ = ' ';
|
|
172
|
+
p = fxDatePrintTime(p, (txInteger)dt.hours, (txInteger)dt.minutes, (txInteger)dt.seconds);
|
|
173
|
+
*p++ = ' ';
|
|
174
|
+
p = fxDatePrintTimezone(p, (txInteger)dt.offset);
|
|
175
|
+
*p = 0;
|
|
176
|
+
fxCopyStringC(the, mxResult, buffer);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
mxPushSlot(mxTarget);
|
|
180
|
+
fxGetPrototypeFromConstructor(the, &mxDatePrototype);
|
|
181
|
+
instance = fxNewDateInstance(the);
|
|
182
|
+
mxPullSlot(mxResult);
|
|
183
|
+
if (c > 1) {
|
|
184
|
+
dt.year = fxDateFullYear(the, mxArgv(0));
|
|
185
|
+
dt.month = fxToNumber(the, mxArgv(1));
|
|
186
|
+
dt.date = (c > 2) ? fxToNumber(the, mxArgv(2)) : 1;
|
|
187
|
+
dt.hours = (c > 3) ? fxToNumber(the, mxArgv(3)) : 0;
|
|
188
|
+
dt.minutes = (c > 4) ? fxToNumber(the, mxArgv(4)) : 0;
|
|
189
|
+
dt.seconds = (c > 5) ?fxToNumber(the, mxArgv(5)) : 0;
|
|
190
|
+
dt.milliseconds = (c > 6) ? fxToNumber(the, mxArgv(6)) : 0;
|
|
191
|
+
instance->next->value.number = fxDateMerge(&dt, 0);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (c > 0) {
|
|
195
|
+
txSlot* slot = mxArgv(0);
|
|
196
|
+
if (slot->kind == XS_REFERENCE_KIND) {
|
|
197
|
+
txSlot* date = slot->value.reference;
|
|
198
|
+
if ((date->next) && (date->next->kind == XS_DATE_KIND)) {
|
|
199
|
+
instance->next->value.number = date->next->value.number;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
fxToPrimitive(the, slot, XS_NO_HINT);
|
|
204
|
+
if ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) {
|
|
205
|
+
mxPushSlot(mxFunction);
|
|
206
|
+
mxDub();
|
|
207
|
+
mxGetID(mxID(_parse));
|
|
208
|
+
mxCall();
|
|
209
|
+
mxPushSlot(slot);
|
|
210
|
+
mxRunCount(1);
|
|
211
|
+
instance->next->value.number = the->stack->value.number;
|
|
212
|
+
mxPop();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
instance->next->value.number = fxDateClip(fxToNumber(the, slot));
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (secure)
|
|
219
|
+
mxTypeError("secure mode");
|
|
220
|
+
instance->next->value.number = fxDateNow();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
void fx_Date_secure(txMachine* the)
|
|
224
|
+
{
|
|
225
|
+
fx_Date_aux(the, 1);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
void fx_Date_now(txMachine* the)
|
|
229
|
+
{
|
|
230
|
+
mxResult->value.number = fxDateNow();
|
|
231
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void fx_Date_now_secure(txMachine* the)
|
|
235
|
+
{
|
|
236
|
+
mxTypeError("secure mode");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
txInteger fx_Date_parse_number(txByte* theCharacter, txString* theString)
|
|
240
|
+
{
|
|
241
|
+
txByte c = *theCharacter;
|
|
242
|
+
txString p = *theString;
|
|
243
|
+
txInteger aResult = c - '0';
|
|
244
|
+
c = c_read8(p++);
|
|
245
|
+
while (('0' <= c) && (c <= '9')) {
|
|
246
|
+
aResult = (aResult * 10) + c - '0';
|
|
247
|
+
c = c_read8(p++);
|
|
248
|
+
}
|
|
249
|
+
*theCharacter = c;
|
|
250
|
+
*theString = p;
|
|
251
|
+
return aResult;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
txInteger fx_Date_parse_fraction(txByte* theCharacter, txString* theString)
|
|
255
|
+
{
|
|
256
|
+
txByte c = *theCharacter;
|
|
257
|
+
txString p = *theString;
|
|
258
|
+
txNumber fraction = 100;
|
|
259
|
+
txNumber aResult = ((c - '0') * fraction);
|
|
260
|
+
c = c_read8(p++);
|
|
261
|
+
while (('0' <= c) && (c <= '9')) {
|
|
262
|
+
fraction /= 10;
|
|
263
|
+
aResult = aResult + ((c - '0') * fraction);
|
|
264
|
+
c = c_read8(p++);
|
|
265
|
+
}
|
|
266
|
+
*theCharacter = c;
|
|
267
|
+
*theString = p;
|
|
268
|
+
return (txInteger)c_trunc(aResult);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
void fx_Date_parse(txMachine* the)
|
|
272
|
+
{
|
|
273
|
+
#define mxDayCount 7
|
|
274
|
+
static const char* const gxDays[mxDayCount] ICACHE_RODATA_ATTR = {
|
|
275
|
+
"monday",
|
|
276
|
+
"tuesday",
|
|
277
|
+
"wednesday",
|
|
278
|
+
"thursday",
|
|
279
|
+
"friday",
|
|
280
|
+
"saturday",
|
|
281
|
+
"sunday"
|
|
282
|
+
};
|
|
283
|
+
#define mxMonthCount 12
|
|
284
|
+
static const char* const gxMonths[mxMonthCount] ICACHE_RODATA_ATTR = {
|
|
285
|
+
"january",
|
|
286
|
+
"february",
|
|
287
|
+
"march",
|
|
288
|
+
"april",
|
|
289
|
+
"may",
|
|
290
|
+
"june",
|
|
291
|
+
"july",
|
|
292
|
+
"august",
|
|
293
|
+
"september",
|
|
294
|
+
"october",
|
|
295
|
+
"november",
|
|
296
|
+
"december"
|
|
297
|
+
};
|
|
298
|
+
#define mxZoneCount 11
|
|
299
|
+
static const char* const gxZones[mxZoneCount] ICACHE_RODATA_ATTR = {
|
|
300
|
+
"gmt", "ut", "utc",
|
|
301
|
+
"est", "edt",
|
|
302
|
+
"cst", "cdt",
|
|
303
|
+
"mst", "mdt",
|
|
304
|
+
"pst", "pdt"
|
|
305
|
+
};
|
|
306
|
+
static const int gxDeltas[mxZoneCount] ICACHE_XS6RO2_ATTR = {
|
|
307
|
+
0, 0, 0,
|
|
308
|
+
-5, -4,
|
|
309
|
+
-6, -5,
|
|
310
|
+
-7, -6,
|
|
311
|
+
-8, -7
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
txString aString;
|
|
315
|
+
txDateTime dt;
|
|
316
|
+
txString p;
|
|
317
|
+
txString q;
|
|
318
|
+
txByte c;
|
|
319
|
+
char buffer[10]; /* base type should be the same as txString */
|
|
320
|
+
txInteger aComment;
|
|
321
|
+
txInteger aDelta;
|
|
322
|
+
txInteger aValue;
|
|
323
|
+
txSize aLength;
|
|
324
|
+
txInteger i;
|
|
325
|
+
txInteger yearSign = 1;
|
|
326
|
+
|
|
327
|
+
if (mxArgc < 1)
|
|
328
|
+
goto fail;
|
|
329
|
+
aString = fxToString(the, mxArgv(0));
|
|
330
|
+
|
|
331
|
+
dt.seconds = -1;
|
|
332
|
+
dt.minutes = -1;
|
|
333
|
+
dt.hours = -1;
|
|
334
|
+
dt.date = -1;
|
|
335
|
+
dt.month = -1;
|
|
336
|
+
dt.year = -1;
|
|
337
|
+
dt.milliseconds = -1;
|
|
338
|
+
aComment = 0;
|
|
339
|
+
aDelta = -1;
|
|
340
|
+
|
|
341
|
+
c = c_read8(aString++);
|
|
342
|
+
while (c) {
|
|
343
|
+
if (c == '(') {
|
|
344
|
+
aComment++;
|
|
345
|
+
c = c_read8(aString++);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
else if (c == ')') {
|
|
349
|
+
if (aComment) {
|
|
350
|
+
aComment--;
|
|
351
|
+
c = c_read8(aString++);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
else
|
|
355
|
+
goto fail;
|
|
356
|
+
}
|
|
357
|
+
else if (aComment) {
|
|
358
|
+
c = c_read8(aString++);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if ((c <= ' ') || (c == ',')) {
|
|
363
|
+
c = c_read8(aString++);
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
else if ((c == '-') | (c == '+')) {
|
|
368
|
+
txInteger aSign;
|
|
369
|
+
if (c == '-')
|
|
370
|
+
aSign = -1;
|
|
371
|
+
else
|
|
372
|
+
aSign = 1;
|
|
373
|
+
c = c_read8(aString++);
|
|
374
|
+
if (('0' <= c) && (c <= '9')) {
|
|
375
|
+
aValue = fx_Date_parse_number(&c, &aString);
|
|
376
|
+
if (c == '-') {
|
|
377
|
+
if (dt.year >= 0)
|
|
378
|
+
goto fail;
|
|
379
|
+
dt.year = aValue;
|
|
380
|
+
yearSign = aSign;
|
|
381
|
+
c = c_read8(aString++);
|
|
382
|
+
if (('0' <= c) && (c <= '9')) {
|
|
383
|
+
dt.month = fx_Date_parse_number(&c, &aString) - 1;
|
|
384
|
+
if (c == '-') {
|
|
385
|
+
c = c_read8(aString++);
|
|
386
|
+
if (('0' <= c) && (c <= '9'))
|
|
387
|
+
dt.date = fx_Date_parse_number(&c, &aString);
|
|
388
|
+
else
|
|
389
|
+
dt.date = 1;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else
|
|
393
|
+
dt.month = 0;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
if ((aDelta != 0) && (aDelta != -1))
|
|
397
|
+
goto fail;
|
|
398
|
+
if (c == ':') {
|
|
399
|
+
aDelta = 60 * aValue;
|
|
400
|
+
c = c_read8(aString++);
|
|
401
|
+
if (('0' <= c) && (c <= '9')) {
|
|
402
|
+
aDelta += fx_Date_parse_number(&c, &aString);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
if (aValue < 24)
|
|
407
|
+
aDelta = aValue * 60;
|
|
408
|
+
else
|
|
409
|
+
aDelta = (aValue % 100) + ((aValue / 100) * 60);
|
|
410
|
+
}
|
|
411
|
+
aDelta *= aSign;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
else
|
|
415
|
+
goto fail;
|
|
416
|
+
}
|
|
417
|
+
else if (('0' <= c) && (c <= '9')) {
|
|
418
|
+
aValue = fx_Date_parse_number(&c, &aString);
|
|
419
|
+
if (c == ':') {
|
|
420
|
+
if (dt.hours >= 0)
|
|
421
|
+
goto fail;
|
|
422
|
+
dt.hours = aValue;
|
|
423
|
+
c = c_read8(aString++);
|
|
424
|
+
if (('0' <= c) && (c <= '9')) {
|
|
425
|
+
dt.minutes = fx_Date_parse_number(&c, &aString);
|
|
426
|
+
if (c == ':') {
|
|
427
|
+
c = c_read8(aString++);
|
|
428
|
+
if (('0' <= c) && (c <= '9')) {
|
|
429
|
+
dt.seconds = fx_Date_parse_number(&c, &aString);
|
|
430
|
+
if (c == '.') {
|
|
431
|
+
c = c_read8(aString++);
|
|
432
|
+
if (('0' <= c) && (c <= '9')) {
|
|
433
|
+
dt.milliseconds = fx_Date_parse_fraction(&c, &aString);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
else
|
|
438
|
+
dt.seconds = 0;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
else
|
|
442
|
+
dt.seconds = 0;
|
|
443
|
+
}
|
|
444
|
+
else if (c == '/') {
|
|
445
|
+
if (dt.year >= 0)
|
|
446
|
+
goto fail;
|
|
447
|
+
dt.year = /*(aValue < 100) ? aValue + 1900 :*/ aValue;
|
|
448
|
+
c = c_read8(aString++);
|
|
449
|
+
if (('0' <= c) && (c <= '9')) {
|
|
450
|
+
dt.month = fx_Date_parse_number(&c, &aString) - 1;
|
|
451
|
+
if (c == '/') {
|
|
452
|
+
c = c_read8(aString++);
|
|
453
|
+
if (('0' <= c) && (c <= '9')) {
|
|
454
|
+
dt.date = fx_Date_parse_number(&c, &aString);
|
|
455
|
+
}
|
|
456
|
+
else
|
|
457
|
+
dt.date = 1;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
else
|
|
461
|
+
dt.month = 0;
|
|
462
|
+
}
|
|
463
|
+
else if (c == '-') {
|
|
464
|
+
if (dt.year >= 0)
|
|
465
|
+
goto fail;
|
|
466
|
+
dt.year = /*(aValue < 100) ? aValue + 1900 :*/ aValue;
|
|
467
|
+
c = c_read8(aString++);
|
|
468
|
+
if (('0' <= c) && (c <= '9')) {
|
|
469
|
+
dt.month = fx_Date_parse_number(&c, &aString) - 1;
|
|
470
|
+
if (c == '-') {
|
|
471
|
+
c = c_read8(aString++);
|
|
472
|
+
if (('0' <= c) && (c <= '9'))
|
|
473
|
+
dt.date = fx_Date_parse_number(&c, &aString);
|
|
474
|
+
else
|
|
475
|
+
dt.date = 1;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
else
|
|
479
|
+
dt.month = 0;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
if (aValue < 70) {
|
|
483
|
+
if (dt.date < 0)
|
|
484
|
+
dt.date = aValue;
|
|
485
|
+
else
|
|
486
|
+
goto fail;
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
if (dt.year < 0)
|
|
490
|
+
dt.year = /*(aValue < 100) ? aValue + 1900 :*/ aValue;
|
|
491
|
+
else
|
|
492
|
+
goto fail;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
else if ((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z'))) {
|
|
497
|
+
txSize cmpLength;
|
|
498
|
+
p = buffer;
|
|
499
|
+
q = p + sizeof(buffer) - 1;
|
|
500
|
+
do {
|
|
501
|
+
if (p == q) goto fail;
|
|
502
|
+
*p++ = (c >= 'a') ? c : (c + ('a' - 'A'));
|
|
503
|
+
c = c_read8(aString++);
|
|
504
|
+
} while ((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')));
|
|
505
|
+
*p = 0;
|
|
506
|
+
aLength = mxPtrDiff(p - (txString)buffer);
|
|
507
|
+
cmpLength = (aLength >= 3) ? aLength : 3;
|
|
508
|
+
if (c_strcmp("am", buffer) == 0) {
|
|
509
|
+
if ((dt.hours < 0) || (12 < dt.hours))
|
|
510
|
+
goto fail;
|
|
511
|
+
if (dt.hours == 12)
|
|
512
|
+
dt.hours = 0;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (c_strcmp("pm", buffer) == 0) {
|
|
516
|
+
if ((dt.hours < 0) || (12 < dt.hours))
|
|
517
|
+
goto fail;
|
|
518
|
+
if (dt.hours != 12)
|
|
519
|
+
dt.hours += 12;
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
for (i = 0; i < mxDayCount; i++)
|
|
523
|
+
if (c_strncmp(gxDays[i], buffer, cmpLength) == 0)
|
|
524
|
+
break;
|
|
525
|
+
if (i < mxDayCount)
|
|
526
|
+
continue;
|
|
527
|
+
for (i = 0; i < mxMonthCount; i++)
|
|
528
|
+
if (c_strncmp(gxMonths[i], buffer, cmpLength) == 0)
|
|
529
|
+
break;
|
|
530
|
+
if (i < mxMonthCount) {
|
|
531
|
+
if (dt.month < 0) {
|
|
532
|
+
dt.month = i;
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
else
|
|
536
|
+
goto fail;
|
|
537
|
+
}
|
|
538
|
+
for (i = 0; i < mxZoneCount; i++)
|
|
539
|
+
if (c_strcmp(gxZones[i], buffer) == 0)
|
|
540
|
+
break;
|
|
541
|
+
if (i < mxZoneCount) {
|
|
542
|
+
if (aDelta == -1) {
|
|
543
|
+
aDelta = gxDeltas[i] * 60;
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
else
|
|
547
|
+
goto fail;
|
|
548
|
+
}
|
|
549
|
+
if (c_strcmp("t", buffer) == 0) {
|
|
550
|
+
if (dt.year < 0)
|
|
551
|
+
goto fail;
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
if (c_strcmp("z", buffer) == 0) {
|
|
555
|
+
if (dt.hours < 0)
|
|
556
|
+
goto fail;
|
|
557
|
+
aDelta = 0;
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
goto fail;
|
|
561
|
+
}
|
|
562
|
+
else
|
|
563
|
+
goto fail;
|
|
564
|
+
}
|
|
565
|
+
if (dt.year < 0)
|
|
566
|
+
goto fail;
|
|
567
|
+
if ((yearSign < 0) && (dt.year == 0))
|
|
568
|
+
goto fail;
|
|
569
|
+
if (dt.month < 0)
|
|
570
|
+
dt.month = 0;
|
|
571
|
+
if (dt.date < 0)
|
|
572
|
+
dt.date = 1;
|
|
573
|
+
if ((aDelta < 0) && (dt.hours < 0) && (dt.minutes < 0) && (dt.seconds < 0) && (dt.milliseconds < 0))
|
|
574
|
+
aDelta = 0;
|
|
575
|
+
if (dt.hours < 0)
|
|
576
|
+
dt.hours = 0;
|
|
577
|
+
if (dt.minutes < 0)
|
|
578
|
+
dt.minutes = 0;
|
|
579
|
+
if (dt.seconds < 0)
|
|
580
|
+
dt.seconds = 0;
|
|
581
|
+
if (dt.milliseconds < 0)
|
|
582
|
+
dt.milliseconds = 0;
|
|
583
|
+
dt.year *= yearSign;
|
|
584
|
+
mxResult->value.number = fxDateMerge(&dt, (aDelta != -1) ? 1 : 0);
|
|
585
|
+
if (aDelta != -1)
|
|
586
|
+
mxResult->value.number -= (txNumber)aDelta * 60000.0;
|
|
587
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
588
|
+
return;
|
|
589
|
+
fail:
|
|
590
|
+
mxResult->value.number = C_NAN;
|
|
591
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
592
|
+
//mxSyntaxError("invalid parameter");
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
void fx_Date_UTC(txMachine* the)
|
|
596
|
+
{
|
|
597
|
+
txInteger c = mxArgc;
|
|
598
|
+
txDateTime dt;
|
|
599
|
+
dt.year = (c > 0) ? fxDateFullYear(the, mxArgv(0)) : C_NAN;
|
|
600
|
+
dt.month = (c > 1) ? fxToNumber(the, mxArgv(1)) : 0;
|
|
601
|
+
dt.date = (c > 2) ? fxToNumber(the, mxArgv(2)) : 1;
|
|
602
|
+
dt.hours = (c > 3) ? fxToNumber(the, mxArgv(3)) : 0;
|
|
603
|
+
dt.minutes = (c > 4) ? fxToNumber(the, mxArgv(4)) : 0;
|
|
604
|
+
dt.seconds = (c > 5) ?fxToNumber(the, mxArgv(5)) : 0;
|
|
605
|
+
dt.milliseconds = (c > 6) ? fxToNumber(the, mxArgv(6)) : 0;
|
|
606
|
+
mxResult->value.number = fxDateMerge(&dt, 1);
|
|
607
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
txBoolean fx_Date_prototype_get_aux(txMachine* the, txDateTime* dt, txBoolean utc, txSlot* slot)
|
|
611
|
+
{
|
|
612
|
+
txSlot* instance = mxThis->value.reference;
|
|
613
|
+
txNumber number;
|
|
614
|
+
if (instance->ID) {
|
|
615
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
616
|
+
if (alias) {
|
|
617
|
+
instance = alias;
|
|
618
|
+
slot = instance->next;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
number = slot->value.number;
|
|
622
|
+
if (c_isnan(number)) {
|
|
623
|
+
mxResult->value.number = C_NAN;
|
|
624
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
625
|
+
return 0;
|
|
626
|
+
}
|
|
627
|
+
fxDateSplit(slot->value.number, utc, dt);
|
|
628
|
+
return 1;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
void fx_Date_prototype_set_aux(txMachine* the, txDateTime* dt, txBoolean utc, txSlot* slot)
|
|
632
|
+
{
|
|
633
|
+
txSlot* instance = mxThis->value.reference;
|
|
634
|
+
txNumber number;
|
|
635
|
+
if (instance->ID) {
|
|
636
|
+
txSlot* alias = the->aliasArray[instance->ID];
|
|
637
|
+
if (alias)
|
|
638
|
+
instance = alias;
|
|
639
|
+
else
|
|
640
|
+
instance = fxAliasInstance(the, instance);
|
|
641
|
+
slot = instance->next;
|
|
642
|
+
}
|
|
643
|
+
number = slot->value.number;
|
|
644
|
+
if (c_isnan(number))
|
|
645
|
+
return;
|
|
646
|
+
if (slot->flag & XS_DONT_SET_FLAG)
|
|
647
|
+
mxTypeError("Date instance is read-only");
|
|
648
|
+
mxResult->value.number = slot->value.number = fxDateMerge(dt, utc);
|
|
649
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
void fx_Date_prototype_getMilliseconds(txMachine* the)
|
|
653
|
+
{
|
|
654
|
+
txDateTime dt;
|
|
655
|
+
txSlot* slot = fxDateCheck(the);
|
|
656
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
657
|
+
mxResult->value.integer = (txInteger)dt.milliseconds;
|
|
658
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
void fx_Date_prototype_getSeconds(txMachine* the)
|
|
663
|
+
{
|
|
664
|
+
txDateTime dt;
|
|
665
|
+
txSlot* slot = fxDateCheck(the);
|
|
666
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
667
|
+
mxResult->value.integer = (txInteger)dt.seconds;
|
|
668
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
void fx_Date_prototype_getMinutes(txMachine* the)
|
|
673
|
+
{
|
|
674
|
+
txDateTime dt;
|
|
675
|
+
txSlot* slot = fxDateCheck(the);
|
|
676
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
677
|
+
mxResult->value.integer = (txInteger)dt.minutes;
|
|
678
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
void fx_Date_prototype_getHours(txMachine* the)
|
|
683
|
+
{
|
|
684
|
+
txDateTime dt;
|
|
685
|
+
txSlot* slot = fxDateCheck(the);
|
|
686
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
687
|
+
mxResult->value.integer = (txInteger)dt.hours;
|
|
688
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
void fx_Date_prototype_getDay(txMachine* the)
|
|
693
|
+
{
|
|
694
|
+
txDateTime dt;
|
|
695
|
+
txSlot* slot = fxDateCheck(the);
|
|
696
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
697
|
+
mxResult->value.integer = dt.day;
|
|
698
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
void fx_Date_prototype_getDate(txMachine* the)
|
|
703
|
+
{
|
|
704
|
+
txDateTime dt;
|
|
705
|
+
txSlot* slot = fxDateCheck(the);
|
|
706
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
707
|
+
mxResult->value.integer = (txInteger)dt.date;
|
|
708
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
void fx_Date_prototype_getMonth(txMachine* the)
|
|
713
|
+
{
|
|
714
|
+
txDateTime dt;
|
|
715
|
+
txSlot* slot = fxDateCheck(the);
|
|
716
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
717
|
+
mxResult->value.integer = (txInteger)dt.month;
|
|
718
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
void fx_Date_prototype_getYear(txMachine* the)
|
|
723
|
+
{
|
|
724
|
+
txDateTime dt;
|
|
725
|
+
txSlot* slot = fxDateCheck(the);
|
|
726
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
727
|
+
mxResult->value.integer = (txInteger)dt.year - 1900;
|
|
728
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
void fx_Date_prototype_getFullYear(txMachine* the)
|
|
733
|
+
{
|
|
734
|
+
txDateTime dt;
|
|
735
|
+
txSlot* slot = fxDateCheck(the);
|
|
736
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
737
|
+
mxResult->value.integer = (txInteger)dt.year;
|
|
738
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
void fx_Date_prototype_getUTCMilliseconds(txMachine* the)
|
|
743
|
+
{
|
|
744
|
+
txDateTime dt;
|
|
745
|
+
txSlot* slot = fxDateCheck(the);
|
|
746
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
747
|
+
mxResult->value.integer = (txInteger)dt.milliseconds;
|
|
748
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
void fx_Date_prototype_getUTCSeconds(txMachine* the)
|
|
753
|
+
{
|
|
754
|
+
txDateTime dt;
|
|
755
|
+
txSlot* slot = fxDateCheck(the);
|
|
756
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
757
|
+
mxResult->value.integer = (txInteger)dt.seconds;
|
|
758
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
void fx_Date_prototype_getUTCMinutes(txMachine* the)
|
|
763
|
+
{
|
|
764
|
+
txDateTime dt;
|
|
765
|
+
txSlot* slot = fxDateCheck(the);
|
|
766
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
767
|
+
mxResult->value.integer = (txInteger)dt.minutes;
|
|
768
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
void fx_Date_prototype_getUTCHours(txMachine* the)
|
|
773
|
+
{
|
|
774
|
+
txDateTime dt;
|
|
775
|
+
txSlot* slot = fxDateCheck(the);
|
|
776
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
777
|
+
mxResult->value.integer = (txInteger)dt.hours;
|
|
778
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
void fx_Date_prototype_getUTCDay(txMachine* the)
|
|
783
|
+
{
|
|
784
|
+
txDateTime dt;
|
|
785
|
+
txSlot* slot = fxDateCheck(the);
|
|
786
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
787
|
+
mxResult->value.integer = dt.day;
|
|
788
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
void fx_Date_prototype_getUTCDate(txMachine* the)
|
|
793
|
+
{
|
|
794
|
+
txDateTime dt;
|
|
795
|
+
txSlot* slot = fxDateCheck(the);
|
|
796
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
797
|
+
mxResult->value.integer = (txInteger)dt.date;
|
|
798
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
void fx_Date_prototype_getUTCMonth(txMachine* the)
|
|
803
|
+
{
|
|
804
|
+
txDateTime dt;
|
|
805
|
+
txSlot* slot = fxDateCheck(the);
|
|
806
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
807
|
+
mxResult->value.integer = (txInteger)dt.month;
|
|
808
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
void fx_Date_prototype_getUTCFullYear(txMachine* the)
|
|
813
|
+
{
|
|
814
|
+
txDateTime dt;
|
|
815
|
+
txSlot* slot = fxDateCheck(the);
|
|
816
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
817
|
+
mxResult->value.integer = (txInteger)dt.year;
|
|
818
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
void fx_Date_prototype_getTimezoneOffset(txMachine* the)
|
|
823
|
+
{
|
|
824
|
+
txDateTime dt;
|
|
825
|
+
txSlot* slot = fxDateCheck(the);
|
|
826
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
827
|
+
mxResult->value.integer = 0 - dt.offset;
|
|
828
|
+
mxResult->kind = XS_INTEGER_KIND;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
void fx_Date_prototype_setMilliseconds(txMachine* the)
|
|
833
|
+
{
|
|
834
|
+
txInteger c = mxArgc;
|
|
835
|
+
txDateTime dt;
|
|
836
|
+
txSlot* slot = fxDateCheck(the);
|
|
837
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
838
|
+
dt.milliseconds = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
839
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
void fx_Date_prototype_setSeconds(txMachine* the)
|
|
843
|
+
{
|
|
844
|
+
txInteger c = mxArgc;
|
|
845
|
+
txDateTime dt;
|
|
846
|
+
txSlot* slot = fxDateCheck(the);
|
|
847
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
848
|
+
dt.seconds = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
849
|
+
if (c > 1) dt.milliseconds = fxToNumber(the, mxArgv(1));
|
|
850
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
void fx_Date_prototype_setMinutes(txMachine* the)
|
|
854
|
+
{
|
|
855
|
+
txInteger c = mxArgc;
|
|
856
|
+
txDateTime dt;
|
|
857
|
+
txSlot* slot = fxDateCheck(the);
|
|
858
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
859
|
+
dt.minutes = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
860
|
+
if (c > 1) dt.seconds = fxToNumber(the, mxArgv(1));
|
|
861
|
+
if (c > 2) dt.milliseconds = fxToNumber(the, mxArgv(2));
|
|
862
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
void fx_Date_prototype_setHours(txMachine* the)
|
|
866
|
+
{
|
|
867
|
+
txInteger c = mxArgc;
|
|
868
|
+
txDateTime dt;
|
|
869
|
+
txSlot* slot = fxDateCheck(the);
|
|
870
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
871
|
+
dt.hours = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
872
|
+
if (c > 1) dt.minutes = fxToNumber(the, mxArgv(1));
|
|
873
|
+
if (c > 2) dt.seconds = fxToNumber(the, mxArgv(2));
|
|
874
|
+
if (c > 3) dt.milliseconds = fxToNumber(the, mxArgv(3));
|
|
875
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
void fx_Date_prototype_setDate(txMachine* the)
|
|
879
|
+
{
|
|
880
|
+
txInteger c = mxArgc;
|
|
881
|
+
txDateTime dt;
|
|
882
|
+
txSlot* slot = fxDateCheck(the);
|
|
883
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
884
|
+
dt.date = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
885
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
void fx_Date_prototype_setMonth(txMachine* the)
|
|
889
|
+
{
|
|
890
|
+
txInteger c = mxArgc;
|
|
891
|
+
txDateTime dt;
|
|
892
|
+
txSlot* slot = fxDateCheck(the);
|
|
893
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
894
|
+
dt.month = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
895
|
+
if (c > 1) dt.date = fxToNumber(the, mxArgv(1));
|
|
896
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
void fx_Date_prototype_setYear(txMachine* the)
|
|
900
|
+
{
|
|
901
|
+
txInteger c = mxArgc;
|
|
902
|
+
txDateTime dt;
|
|
903
|
+
txSlot* slot = fxDateCheck(the);
|
|
904
|
+
if (c_isnan(slot->value.number)) {
|
|
905
|
+
slot->value.number = 0;
|
|
906
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
907
|
+
}
|
|
908
|
+
else
|
|
909
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
910
|
+
dt.year = (mxArgc > 0) ? fxDateFullYear(the, mxArgv(0)) : C_NAN;
|
|
911
|
+
if (c > 1) dt.month = fxToNumber(the, mxArgv(1));
|
|
912
|
+
if (c > 2) dt.date = fxToNumber(the, mxArgv(2));
|
|
913
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
void fx_Date_prototype_setFullYear(txMachine* the)
|
|
917
|
+
{
|
|
918
|
+
txInteger c = mxArgc;
|
|
919
|
+
txDateTime dt;
|
|
920
|
+
txSlot* slot = fxDateCheck(the);
|
|
921
|
+
if (c_isnan(slot->value.number)) {
|
|
922
|
+
slot->value.number = 0;
|
|
923
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
924
|
+
}
|
|
925
|
+
else
|
|
926
|
+
fx_Date_prototype_get_aux(the, &dt, 0, slot);
|
|
927
|
+
dt.year = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
928
|
+
if (c > 1) dt.month = fxToNumber(the, mxArgv(1));
|
|
929
|
+
if (c > 2) dt.date = fxToNumber(the, mxArgv(2));
|
|
930
|
+
fx_Date_prototype_set_aux(the, &dt, 0, slot);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
void fx_Date_prototype_setTime(txMachine* the)
|
|
934
|
+
{
|
|
935
|
+
txSlot* slot = fxDateCheck(the);
|
|
936
|
+
if (!slot) mxTypeError("this is no date");
|
|
937
|
+
if (mxArgc < 1)
|
|
938
|
+
slot->value.number = C_NAN;
|
|
939
|
+
else {
|
|
940
|
+
txNumber number = fxToNumber(the, mxArgv(0));
|
|
941
|
+
int fpclass = c_fpclassify(number);
|
|
942
|
+
if (fpclass != FP_NAN) {
|
|
943
|
+
if (c_fabs(number) > 8.64e15)
|
|
944
|
+
number = C_NAN;
|
|
945
|
+
else
|
|
946
|
+
number = c_trunc(number);
|
|
947
|
+
}
|
|
948
|
+
slot->value.number = number;
|
|
949
|
+
}
|
|
950
|
+
mxResult->value.number = slot->value.number;
|
|
951
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
void fx_Date_prototype_setUTCMilliseconds(txMachine* the)
|
|
955
|
+
{
|
|
956
|
+
txInteger c = mxArgc;
|
|
957
|
+
txDateTime dt;
|
|
958
|
+
txSlot* slot = fxDateCheck(the);
|
|
959
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
960
|
+
dt.milliseconds = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
961
|
+
fx_Date_prototype_set_aux(the, &dt, 1, slot);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
void fx_Date_prototype_setUTCSeconds(txMachine* the)
|
|
965
|
+
{
|
|
966
|
+
txInteger c = mxArgc;
|
|
967
|
+
txDateTime dt;
|
|
968
|
+
txSlot* slot = fxDateCheck(the);
|
|
969
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
970
|
+
dt.seconds = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
971
|
+
if (c > 1) dt.milliseconds = fxToNumber(the, mxArgv(1));
|
|
972
|
+
fx_Date_prototype_set_aux(the, &dt, 1, slot);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
void fx_Date_prototype_setUTCMinutes(txMachine* the)
|
|
976
|
+
{
|
|
977
|
+
txInteger c = mxArgc;
|
|
978
|
+
txDateTime dt;
|
|
979
|
+
txSlot* slot = fxDateCheck(the);
|
|
980
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
981
|
+
dt.minutes = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
982
|
+
if (c > 1) dt.seconds = fxToNumber(the, mxArgv(1));
|
|
983
|
+
if (c > 2) dt.milliseconds = fxToNumber(the, mxArgv(2));
|
|
984
|
+
fx_Date_prototype_set_aux(the, &dt, 1, slot);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
void fx_Date_prototype_setUTCHours(txMachine* the)
|
|
988
|
+
{
|
|
989
|
+
txInteger c = mxArgc;
|
|
990
|
+
txDateTime dt;
|
|
991
|
+
txSlot* slot = fxDateCheck(the);
|
|
992
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
993
|
+
dt.hours = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
994
|
+
if (c > 1) dt.minutes = fxToNumber(the, mxArgv(1));
|
|
995
|
+
if (c > 2) dt.seconds = fxToNumber(the, mxArgv(2));
|
|
996
|
+
if (c > 3) dt.milliseconds = fxToNumber(the, mxArgv(3));
|
|
997
|
+
fx_Date_prototype_set_aux(the, &dt, 1, slot);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
void fx_Date_prototype_setUTCDate(txMachine* the)
|
|
1001
|
+
{
|
|
1002
|
+
txInteger c = mxArgc;
|
|
1003
|
+
txDateTime dt;
|
|
1004
|
+
txSlot* slot = fxDateCheck(the);
|
|
1005
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
1006
|
+
dt.date = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
1007
|
+
fx_Date_prototype_set_aux(the, &dt, 1, slot);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
void fx_Date_prototype_setUTCMonth(txMachine* the)
|
|
1011
|
+
{
|
|
1012
|
+
txInteger c = mxArgc;
|
|
1013
|
+
txDateTime dt;
|
|
1014
|
+
txSlot* slot = fxDateCheck(the);
|
|
1015
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
1016
|
+
dt.month = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
1017
|
+
if (c > 1) dt.date = fxToNumber(the, mxArgv(1));
|
|
1018
|
+
fx_Date_prototype_set_aux(the, &dt, 1, slot);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
void fx_Date_prototype_setUTCFullYear(txMachine* the)
|
|
1022
|
+
{
|
|
1023
|
+
txInteger c = mxArgc;
|
|
1024
|
+
txDateTime dt;
|
|
1025
|
+
txSlot* slot = fxDateCheck(the);
|
|
1026
|
+
if (c_isnan(slot->value.number)) slot->value.number = 0;
|
|
1027
|
+
fx_Date_prototype_get_aux(the, &dt, 1, slot);
|
|
1028
|
+
dt.year = (c > 0) ? fxToNumber(the, mxArgv(0)) : C_NAN;
|
|
1029
|
+
if (c > 1) dt.month = fxToNumber(the, mxArgv(1));
|
|
1030
|
+
if (c > 2) dt.date = fxToNumber(the, mxArgv(2));
|
|
1031
|
+
fx_Date_prototype_set_aux(the, &dt, 1, slot);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
void fx_Date_prototype_toDateString(txMachine* the)
|
|
1035
|
+
{
|
|
1036
|
+
char buffer[256];
|
|
1037
|
+
txDateTime dt;
|
|
1038
|
+
txSlot* slot = fxDateCheck(the);
|
|
1039
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
1040
|
+
txString p = buffer;
|
|
1041
|
+
p = fxDatePrintDay(p, dt.day);
|
|
1042
|
+
*p++ = ' ';
|
|
1043
|
+
p = fxDatePrintDate(p, (txInteger)dt.year, (txInteger)dt.month, (txInteger)dt.date);
|
|
1044
|
+
*p = 0;
|
|
1045
|
+
}
|
|
1046
|
+
else
|
|
1047
|
+
c_strcpy(buffer, "Invalid Date");
|
|
1048
|
+
fxCopyStringC(the, mxResult, buffer);
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
void fx_Date_prototype_toISOString(txMachine* the)
|
|
1052
|
+
{
|
|
1053
|
+
char buffer[256];
|
|
1054
|
+
txDateTime dt;
|
|
1055
|
+
txSlot* slot = fxDateCheck(the);
|
|
1056
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
1057
|
+
txString p = buffer;
|
|
1058
|
+
p = fxDatePrintYear(p, (txInteger)dt.year);
|
|
1059
|
+
*p++ = '-';
|
|
1060
|
+
p = fxDatePrint2Digits(p, (txInteger)dt.month + 1);
|
|
1061
|
+
*p++ = '-';
|
|
1062
|
+
p = fxDatePrint2Digits(p, (txInteger)dt.date);
|
|
1063
|
+
*p++ = 'T';
|
|
1064
|
+
p = fxDatePrintTime(p, (txInteger)dt.hours, (txInteger)dt.minutes, (txInteger)dt.seconds);
|
|
1065
|
+
*p++ = '.';
|
|
1066
|
+
p = fxDatePrint3Digits(p, (txInteger)dt.milliseconds);
|
|
1067
|
+
*p++ = 'Z';
|
|
1068
|
+
*p = 0;
|
|
1069
|
+
}
|
|
1070
|
+
else
|
|
1071
|
+
mxRangeError("invalid date");
|
|
1072
|
+
fxCopyStringC(the, mxResult, buffer);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
void fx_Date_prototype_toJSON(txMachine* the)
|
|
1076
|
+
{
|
|
1077
|
+
fxToInstance(the, mxThis);
|
|
1078
|
+
mxPushSlot(mxThis);
|
|
1079
|
+
fxToPrimitive(the, the->stack, XS_NUMBER_HINT);
|
|
1080
|
+
if ((the->stack->kind == XS_NUMBER_KIND) && !c_isfinite(the->stack->value.number)) {
|
|
1081
|
+
mxPop();
|
|
1082
|
+
mxResult->kind = XS_NULL_KIND;
|
|
1083
|
+
}
|
|
1084
|
+
else {
|
|
1085
|
+
mxPop();
|
|
1086
|
+
mxPushSlot(mxThis);
|
|
1087
|
+
mxDub();
|
|
1088
|
+
mxGetID(mxID(_toISOString));
|
|
1089
|
+
mxCall();
|
|
1090
|
+
mxRunCount(0);
|
|
1091
|
+
mxPullSlot(mxResult);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
void fx_Date_prototype_toPrimitive(txMachine* the)
|
|
1096
|
+
{
|
|
1097
|
+
if (mxIsReference(mxThis)) {
|
|
1098
|
+
txInteger hint = XS_NO_HINT;
|
|
1099
|
+
txInteger ids[2], i;
|
|
1100
|
+
if (mxArgc > 0) {
|
|
1101
|
+
txSlot* slot = mxArgv(0);
|
|
1102
|
+
if ((slot->kind == XS_STRING_KIND) || (slot->kind == XS_STRING_X_KIND)) {
|
|
1103
|
+
if (!c_strcmp(slot->value.string, "default"))
|
|
1104
|
+
hint = XS_STRING_HINT;
|
|
1105
|
+
else if (!c_strcmp(slot->value.string, "number"))
|
|
1106
|
+
hint = XS_NUMBER_HINT;
|
|
1107
|
+
else if (!c_strcmp(slot->value.string, "string"))
|
|
1108
|
+
hint = XS_STRING_HINT;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
if (hint == XS_STRING_HINT) {
|
|
1112
|
+
ids[0] = mxID(_toString);
|
|
1113
|
+
ids[1] = mxID(_valueOf);
|
|
1114
|
+
}
|
|
1115
|
+
else if (hint == XS_NUMBER_HINT) {
|
|
1116
|
+
ids[0] = mxID(_valueOf);
|
|
1117
|
+
ids[1] = mxID(_toString);
|
|
1118
|
+
}
|
|
1119
|
+
else
|
|
1120
|
+
mxTypeError("invalid hint");
|
|
1121
|
+
for (i = 0; i < 2; i++) {
|
|
1122
|
+
mxPushSlot(mxThis);
|
|
1123
|
+
mxPushSlot(mxThis);
|
|
1124
|
+
mxGetID(ids[i]);
|
|
1125
|
+
if (fxIsCallable(the, the->stack)) {
|
|
1126
|
+
mxCall();
|
|
1127
|
+
mxRunCount(0);
|
|
1128
|
+
if (mxIsReference(the->stack))
|
|
1129
|
+
mxPop();
|
|
1130
|
+
else {
|
|
1131
|
+
mxPullSlot(mxResult);
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
else {
|
|
1136
|
+
mxPop();
|
|
1137
|
+
mxPop();
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
if (hint == XS_STRING_HINT)
|
|
1141
|
+
mxTypeError("cannot coerce object to string");
|
|
1142
|
+
else
|
|
1143
|
+
mxTypeError("cannot coerce object to number");
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
mxTypeError("invalid this");
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
void fx_Date_prototype_toString(txMachine* the)
|
|
1151
|
+
{
|
|
1152
|
+
char buffer[256];
|
|
1153
|
+
txDateTime dt;
|
|
1154
|
+
txSlot* slot = fxDateCheck(the);
|
|
1155
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
1156
|
+
txString p = buffer;
|
|
1157
|
+
p = fxDatePrintDay(p, dt.day);
|
|
1158
|
+
*p++ = ' ';
|
|
1159
|
+
p = fxDatePrintDate(p, (txInteger)dt.year, (txInteger)dt.month, (txInteger)dt.date);
|
|
1160
|
+
*p++ = ' ';
|
|
1161
|
+
p = fxDatePrintTime(p, (txInteger)dt.hours, (txInteger)dt.minutes, (txInteger)dt.seconds);
|
|
1162
|
+
*p++ = ' ';
|
|
1163
|
+
p = fxDatePrintTimezone(p, (txInteger)dt.offset);
|
|
1164
|
+
*p = 0;
|
|
1165
|
+
}
|
|
1166
|
+
else
|
|
1167
|
+
c_strcpy(buffer, "Invalid Date");
|
|
1168
|
+
fxCopyStringC(the, mxResult, buffer);
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
void fx_Date_prototype_toTimeString(txMachine* the)
|
|
1172
|
+
{
|
|
1173
|
+
char buffer[256];
|
|
1174
|
+
txDateTime dt;
|
|
1175
|
+
txSlot* slot = fxDateCheck(the);
|
|
1176
|
+
if (fx_Date_prototype_get_aux(the, &dt, 0, slot)) {
|
|
1177
|
+
txString p = buffer;
|
|
1178
|
+
p = fxDatePrintTime(p, (txInteger)dt.hours, (txInteger)dt.minutes, (txInteger)dt.seconds);
|
|
1179
|
+
*p++ = ' ';
|
|
1180
|
+
p = fxDatePrintTimezone(p, (txInteger)dt.offset);
|
|
1181
|
+
*p = 0;
|
|
1182
|
+
}
|
|
1183
|
+
else
|
|
1184
|
+
c_strcpy(buffer, "Invalid Date");
|
|
1185
|
+
fxCopyStringC(the, mxResult, buffer);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
void fx_Date_prototype_toUTCString(txMachine* the)
|
|
1189
|
+
{
|
|
1190
|
+
char buffer[256];
|
|
1191
|
+
txDateTime dt;
|
|
1192
|
+
txSlot* slot = fxDateCheck(the);
|
|
1193
|
+
if (fx_Date_prototype_get_aux(the, &dt, 1, slot)) {
|
|
1194
|
+
txString p = buffer;
|
|
1195
|
+
p = fxDatePrintDay(p, dt.day);
|
|
1196
|
+
*p++ = ',';
|
|
1197
|
+
*p++ = ' ';
|
|
1198
|
+
p = fxDatePrintDateUTC(p, (txInteger)dt.year, (txInteger)dt.month, (txInteger)dt.date);
|
|
1199
|
+
*p++ = ' ';
|
|
1200
|
+
p = fxDatePrintTime(p, (txInteger)dt.hours, (txInteger)dt.minutes, (txInteger)dt.seconds);
|
|
1201
|
+
*p++ = ' ';
|
|
1202
|
+
*p++ = 'G';
|
|
1203
|
+
*p++ = 'M';
|
|
1204
|
+
*p++ = 'T';
|
|
1205
|
+
*p = 0;
|
|
1206
|
+
}
|
|
1207
|
+
else
|
|
1208
|
+
c_strcpy(buffer, "Invalid Date");
|
|
1209
|
+
fxCopyStringC(the, mxResult, buffer);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
void fx_Date_prototype_valueOf(txMachine* the)
|
|
1213
|
+
{
|
|
1214
|
+
txSlot* slot = fxDateCheck(the);
|
|
1215
|
+
mxResult->kind = XS_NUMBER_KIND;
|
|
1216
|
+
mxResult->value = slot->value;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// Thanks Google V8 for the years offset
|
|
1220
|
+
// Thanks Mozilla JS for the similar years
|
|
1221
|
+
|
|
1222
|
+
static const txString gxDayNames[] ICACHE_XS6RO2_ATTR = {
|
|
1223
|
+
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
1224
|
+
};
|
|
1225
|
+
static const txString gxMonthNames[] ICACHE_XS6RO2_ATTR = {
|
|
1226
|
+
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
1227
|
+
};
|
|
1228
|
+
static const txInteger gxCommonYearMonthsDays[12] ICACHE_XS6RO2_ATTR = {
|
|
1229
|
+
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
|
1230
|
+
};
|
|
1231
|
+
static const txInteger gxLeapYearMonthsDays[12] ICACHE_XS6RO2_ATTR = {
|
|
1232
|
+
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
|
|
1233
|
+
};
|
|
1234
|
+
static const txInteger gxSimilarCommonYears[7] ICACHE_XS6RO2_ATTR = {
|
|
1235
|
+
1978, 1973, 1974, 1975, 1981, 1971, 1977
|
|
1236
|
+
};
|
|
1237
|
+
static const txInteger gxSimilarLeapYears[7] ICACHE_XS6RO2_ATTR = {
|
|
1238
|
+
1984, 1996, 1980, 1992, 1976, 1988, 1972
|
|
1239
|
+
};
|
|
1240
|
+
|
|
1241
|
+
#define mx1YearDays 365
|
|
1242
|
+
#define mx4YearsDays ((4 * mx1YearDays) + 1)
|
|
1243
|
+
#define mx100YearsDays ((25 * mx4YearsDays) - 1)
|
|
1244
|
+
#define mx400YearsDays ((4 * mx100YearsDays) + 1)
|
|
1245
|
+
#define mxDayMilliseconds 86400000.0
|
|
1246
|
+
#define mxYearDays(YEAR) \
|
|
1247
|
+
((365 * (YEAR)) + ((YEAR) / 4) - ((YEAR) / 100) + ((YEAR) / 400) + 1)
|
|
1248
|
+
#define mxIsLeapYear(YEAR) \
|
|
1249
|
+
(((YEAR) % 4) ? 0 : ((YEAR) % 100) ? 1 : ((YEAR) % 400) ? 0 : 1)
|
|
1250
|
+
#define mxYearsOffset 400000
|
|
1251
|
+
|
|
1252
|
+
txSlot* fxDateCheck(txMachine* the)
|
|
1253
|
+
{
|
|
1254
|
+
txSlot* it = mxThis;
|
|
1255
|
+
if (it->kind == XS_REFERENCE_KIND) {
|
|
1256
|
+
txSlot* instance = it->value.reference;
|
|
1257
|
+
it = instance->next;
|
|
1258
|
+
if ((it) && (it->flag & XS_INTERNAL_FLAG) && (it->kind == XS_DATE_KIND))
|
|
1259
|
+
return it;
|
|
1260
|
+
}
|
|
1261
|
+
mxTypeError("this is no date");
|
|
1262
|
+
return C_NULL;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
txNumber fxDateClip(txNumber value)
|
|
1266
|
+
{
|
|
1267
|
+
if (!c_isfinite(value))
|
|
1268
|
+
value = C_NAN;
|
|
1269
|
+
else if (c_fabs(value) > 8.64e15)
|
|
1270
|
+
value = C_NAN;
|
|
1271
|
+
else {
|
|
1272
|
+
value = c_trunc(value);
|
|
1273
|
+
if (value == 0)
|
|
1274
|
+
value = 0;
|
|
1275
|
+
}
|
|
1276
|
+
return value;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
txNumber fxDateFullYear(txMachine* the, txSlot* slot)
|
|
1280
|
+
{
|
|
1281
|
+
txNumber result = fxToNumber(the, slot);
|
|
1282
|
+
if (c_isfinite(result)) {
|
|
1283
|
+
txInteger value = fxToInteger(the, slot);
|
|
1284
|
+
if ((0 <= value) && (value <= 99))
|
|
1285
|
+
result = 1900 + value;
|
|
1286
|
+
}
|
|
1287
|
+
return result;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
txNumber fxDateMerge(txDateTime* dt, txBoolean utc)
|
|
1291
|
+
{
|
|
1292
|
+
txInteger year, month, leap;
|
|
1293
|
+
txNumber value;
|
|
1294
|
+
if ((!c_isfinite(dt->year))
|
|
1295
|
+
|| (!c_isfinite(dt->month))
|
|
1296
|
+
|| (!c_isfinite(dt->date))
|
|
1297
|
+
|| (!c_isfinite(dt->hours))
|
|
1298
|
+
|| (!c_isfinite(dt->minutes))
|
|
1299
|
+
|| (!c_isfinite(dt->seconds))
|
|
1300
|
+
|| (!c_isfinite(dt->milliseconds)))
|
|
1301
|
+
return C_NAN;
|
|
1302
|
+
year = (txInteger)c_trunc(dt->year);
|
|
1303
|
+
month = (txInteger)c_trunc(dt->month);
|
|
1304
|
+
year += month / 12;
|
|
1305
|
+
month %= 12;
|
|
1306
|
+
if (month < 0) {
|
|
1307
|
+
year--;
|
|
1308
|
+
month += 12;
|
|
1309
|
+
}
|
|
1310
|
+
leap = mxIsLeapYear(year);
|
|
1311
|
+
year += mxYearsOffset - 1;
|
|
1312
|
+
value = mxYearDays(year) - mxYearDays(1970 + mxYearsOffset - 1);
|
|
1313
|
+
if (leap)
|
|
1314
|
+
value += gxLeapYearMonthsDays[month];
|
|
1315
|
+
else
|
|
1316
|
+
value += gxCommonYearMonthsDays[month];
|
|
1317
|
+
value += c_trunc(dt->date) - 1;
|
|
1318
|
+
value *= mxDayMilliseconds;
|
|
1319
|
+
value += c_trunc(dt->hours) * 60 * 60 * 1000;
|
|
1320
|
+
value += c_trunc(dt->minutes) * 60 * 1000;
|
|
1321
|
+
value += c_trunc(dt->seconds) * 1000;
|
|
1322
|
+
value += c_trunc(dt->milliseconds);
|
|
1323
|
+
if (!utc) {
|
|
1324
|
+
txNumber former = value;
|
|
1325
|
+
txInteger similar;
|
|
1326
|
+
c_tm tm;
|
|
1327
|
+
c_time_t time;
|
|
1328
|
+
fxDateSplit(value, 1, dt);
|
|
1329
|
+
similar = fxDateSimilarYear((txInteger)dt->year);
|
|
1330
|
+
c_memset(&tm, 0, sizeof(c_tm));
|
|
1331
|
+
tm.tm_year = similar - 1900;
|
|
1332
|
+
tm.tm_mon = (txInteger)dt->month;
|
|
1333
|
+
tm.tm_mday = (txInteger)dt->date;
|
|
1334
|
+
tm.tm_hour = (txInteger)dt->hours;
|
|
1335
|
+
tm.tm_min = (txInteger)dt->minutes;
|
|
1336
|
+
tm.tm_sec = (txInteger)dt->seconds;
|
|
1337
|
+
tm.tm_isdst =-1;
|
|
1338
|
+
time = c_mktime(&tm);
|
|
1339
|
+
if (time == -1)
|
|
1340
|
+
value = NAN;
|
|
1341
|
+
else {
|
|
1342
|
+
value = (txNumber)time;
|
|
1343
|
+
value *= 1000;
|
|
1344
|
+
value += dt->milliseconds;
|
|
1345
|
+
if (similar != year) {
|
|
1346
|
+
dt->year = similar;
|
|
1347
|
+
value += former - fxDateMerge(dt, 1);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
return fxDateClip(value);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
txNumber fxDateNow()
|
|
1355
|
+
{
|
|
1356
|
+
c_timeval tv;
|
|
1357
|
+
c_gettimeofday(&tv, NULL);
|
|
1358
|
+
return fxDateClip(((txNumber)(tv.tv_sec) * 1000.0) + ((txNumber)(tv.tv_usec / 1000)));
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
txString fxDatePrint2Digits(txString p, txInteger value)
|
|
1362
|
+
{
|
|
1363
|
+
*p++ = '0' + value / 10;
|
|
1364
|
+
*p++ = '0' + value % 10;
|
|
1365
|
+
return p;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
txString fxDatePrint3Digits(txString p, txInteger value)
|
|
1369
|
+
{
|
|
1370
|
+
*p++ = '0' + value / 100;
|
|
1371
|
+
return fxDatePrint2Digits(p, value % 100);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
txString fxDatePrint4Digits(txString p, txInteger value)
|
|
1375
|
+
{
|
|
1376
|
+
*p++ = '0' + value / 1000;
|
|
1377
|
+
return fxDatePrint3Digits(p, value % 1000);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
txString fxDatePrintDate(txString p, txInteger year, txInteger month, txInteger date)
|
|
1381
|
+
{
|
|
1382
|
+
c_strcpy(p, gxMonthNames[month]);
|
|
1383
|
+
p += 3;
|
|
1384
|
+
*p++ = ' ';
|
|
1385
|
+
p = fxDatePrint2Digits(p, date);
|
|
1386
|
+
*p++ = ' ';
|
|
1387
|
+
p = fxDatePrintYear(p, year);
|
|
1388
|
+
return p;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
txString fxDatePrintDateUTC(txString p, txInteger year, txInteger month, txInteger date)
|
|
1392
|
+
{
|
|
1393
|
+
p = fxDatePrint2Digits(p, date);
|
|
1394
|
+
*p++ = ' ';
|
|
1395
|
+
c_strcpy(p, gxMonthNames[month]);
|
|
1396
|
+
p += 3;
|
|
1397
|
+
*p++ = ' ';
|
|
1398
|
+
p = fxDatePrintYear(p, year);
|
|
1399
|
+
return p;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
txString fxDatePrintDay(txString p, txInteger day)
|
|
1403
|
+
{
|
|
1404
|
+
c_strcpy(p, gxDayNames[day]);
|
|
1405
|
+
p += 3;
|
|
1406
|
+
return p;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
txString fxDatePrintTime(txString p, txInteger hours, txInteger minutes, txInteger seconds)
|
|
1410
|
+
{
|
|
1411
|
+
p = fxDatePrint2Digits(p, hours);
|
|
1412
|
+
*p++ = ':';
|
|
1413
|
+
p = fxDatePrint2Digits(p, minutes);
|
|
1414
|
+
*p++ = ':';
|
|
1415
|
+
p = fxDatePrint2Digits(p, seconds);
|
|
1416
|
+
return p;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
txString fxDatePrintTimezone(txString p, txInteger offset)
|
|
1420
|
+
{
|
|
1421
|
+
*p++ = 'G';
|
|
1422
|
+
*p++ = 'M';
|
|
1423
|
+
*p++ = 'T';
|
|
1424
|
+
if (offset < 0) {
|
|
1425
|
+
offset = 0 - offset;
|
|
1426
|
+
*p++ = '-';
|
|
1427
|
+
}
|
|
1428
|
+
else
|
|
1429
|
+
*p++ = '+';
|
|
1430
|
+
p = fxDatePrint2Digits(p, offset / 60);
|
|
1431
|
+
p = fxDatePrint2Digits(p, offset % 60);
|
|
1432
|
+
return p;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
txString fxDatePrintYear(txString p, txInteger value)
|
|
1436
|
+
{
|
|
1437
|
+
if ((value < 0) || (9999 < value)) {
|
|
1438
|
+
if (value < 0) {
|
|
1439
|
+
*p++ = '-';
|
|
1440
|
+
value = -value;
|
|
1441
|
+
}
|
|
1442
|
+
else
|
|
1443
|
+
*p++ = '+';
|
|
1444
|
+
if (99999 < value) {
|
|
1445
|
+
*p++ = '0' + value / 100000;
|
|
1446
|
+
value %= 100000;
|
|
1447
|
+
}
|
|
1448
|
+
if (9999 < value) {
|
|
1449
|
+
*p++ = '0' + value / 10000;
|
|
1450
|
+
value %= 10000;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return fxDatePrint4Digits(p, value);
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
txInteger fxDateSimilarYear(txInteger year)
|
|
1457
|
+
{
|
|
1458
|
+
txInteger leap, day;
|
|
1459
|
+
if ((1970 <= year) && (year < 2038))
|
|
1460
|
+
return year;
|
|
1461
|
+
leap = mxIsLeapYear(year);
|
|
1462
|
+
year += mxYearsOffset - 1;
|
|
1463
|
+
day = mxYearDays(year) - mxYearDays(1970 + mxYearsOffset - 1);
|
|
1464
|
+
day = (day + 4) % 7;
|
|
1465
|
+
if (day < 0)
|
|
1466
|
+
day += 7;
|
|
1467
|
+
return (leap) ? gxSimilarLeapYears[day] : gxSimilarCommonYears[day];
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
void fxDateSplit(txNumber value, txBoolean utc, txDateTime* dt)
|
|
1471
|
+
{
|
|
1472
|
+
txInteger date, time, year, leap, month;
|
|
1473
|
+
const txInteger* monthsDays;
|
|
1474
|
+
date = (txInteger)c_trunc(value / mxDayMilliseconds);
|
|
1475
|
+
time = (txInteger)c_fmod(value, mxDayMilliseconds);
|
|
1476
|
+
if (time < 0) {
|
|
1477
|
+
date--;
|
|
1478
|
+
time += (txInteger)mxDayMilliseconds;
|
|
1479
|
+
}
|
|
1480
|
+
dt->offset = 0;
|
|
1481
|
+
dt->day = (date + 4) % 7;
|
|
1482
|
+
if (dt->day < 0)
|
|
1483
|
+
dt->day += 7;
|
|
1484
|
+
dt->milliseconds = time % 1000;
|
|
1485
|
+
time /= 1000;
|
|
1486
|
+
dt->seconds = time % 60;
|
|
1487
|
+
time /= 60;
|
|
1488
|
+
dt->minutes = time % 60;
|
|
1489
|
+
time /= 60;
|
|
1490
|
+
dt->hours = time;
|
|
1491
|
+
date += mxYearDays(1970 + mxYearsOffset);
|
|
1492
|
+
year = 400 * (date / mx400YearsDays);
|
|
1493
|
+
date %= mx400YearsDays;
|
|
1494
|
+
date--;
|
|
1495
|
+
year += 100 * (date / mx100YearsDays);
|
|
1496
|
+
date %= mx100YearsDays;
|
|
1497
|
+
date++;
|
|
1498
|
+
year += 4 * (date / mx4YearsDays);
|
|
1499
|
+
date %= mx4YearsDays;
|
|
1500
|
+
date--;
|
|
1501
|
+
year += date / mx1YearDays;
|
|
1502
|
+
date %= mx1YearDays;
|
|
1503
|
+
year -= mxYearsOffset;
|
|
1504
|
+
leap = mxIsLeapYear(year);
|
|
1505
|
+
date += leap;
|
|
1506
|
+
monthsDays = leap ? gxLeapYearMonthsDays : gxCommonYearMonthsDays;
|
|
1507
|
+
for (month = 0; month < 11; month++) {
|
|
1508
|
+
if (date < monthsDays[month + 1])
|
|
1509
|
+
break;
|
|
1510
|
+
}
|
|
1511
|
+
date -= monthsDays[month];
|
|
1512
|
+
dt->date = date + 1;
|
|
1513
|
+
dt->month = month;
|
|
1514
|
+
dt->year = year;
|
|
1515
|
+
if (!utc) {
|
|
1516
|
+
txNumber former = value;
|
|
1517
|
+
txInteger similar;
|
|
1518
|
+
c_time_t time;
|
|
1519
|
+
c_tm tm;
|
|
1520
|
+
similar = fxDateSimilarYear(year);
|
|
1521
|
+
if (similar != year) {
|
|
1522
|
+
dt->year = similar;
|
|
1523
|
+
value = fxDateMerge(dt, 1);
|
|
1524
|
+
}
|
|
1525
|
+
time = (txInteger)c_floor(value / 1000.0);
|
|
1526
|
+
tm = *c_localtime(&time);
|
|
1527
|
+
dt->milliseconds = c_floor(c_fmod(value, 1000.0));
|
|
1528
|
+
dt->day = tm.tm_wday;
|
|
1529
|
+
dt->seconds = tm.tm_sec;
|
|
1530
|
+
dt->minutes = tm.tm_min;
|
|
1531
|
+
dt->hours = tm.tm_hour;
|
|
1532
|
+
dt->date = tm.tm_mday;
|
|
1533
|
+
dt->month = tm.tm_mon;
|
|
1534
|
+
dt->year = tm.tm_year + 1900 + year - similar;
|
|
1535
|
+
dt->offset = (txInteger)c_trunc((fxDateMerge(dt, 1) - former) / 60000.0);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|