A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/signumsoftware/framework/commit/b2096177de9f84c91d226e1a6080386c55566d2a below:

replace moment for luxon · signumsoftware/framework@b209617 · GitHub

1 -

import * as moment from "moment"

1 +

import { DateTime } from 'luxon';

2 2 3 3

import * as ReactWidgets from 'react-widgets';

4 4 5 5

export function configure() {

6 6 7 -

if (typeof moment !== 'function') throw new TypeError('You must provide a valid moment object');

8 - 9 -

const localField = (m: moment.Moment) => m.locale || m.lang,

10 -

hasLocaleData = !!moment.localeData;

11 - 12 -

if (!hasLocaleData) throw new TypeError('The Moment localizer depends on the `localeData` api, please provide a moment object v2.2.0 or higher');

13 - 14 -

function getMoment(culture: string, value: any, format: string | undefined) {

15 -

return culture ? localField(moment(value, format))(culture) : moment(value, format);

16 -

}

17 7 18 8

function endOfDecade(date: Date) {

19 -

return moment(date).add(10, 'year').add(-1, 'millisecond').toDate();

9 +

return DateTime.fromJSDate(date).plus({ years: 10 }).minus({ millisecond: 1 }).toJSDate();

20 10

}

21 11 22 12

function endOfCentury(date: Date) {

23 -

return moment(date).add(100, 'year').add(-1, 'millisecond').toDate();

13 +

return DateTime.fromJSDate(date).plus({ years: 100 }).minus({ millisecond: 1 }).toJSDate();

24 14

}

25 15 26 16

const localizer = {

27 17

formats: {

28 -

date: 'L',

29 -

time: 'LT',

30 -

'default': 'lll',

31 -

header: 'MMMM YYYY',

32 -

footer: 'LL',

33 -

weekday: 'dd',

34 -

dayOfMonth: 'DD',

18 +

date: 'D',

19 +

time: 't',

20 +

'default': 'FF',

21 +

header: 'MMMM yyyy',

22 +

footer: 'DDD',

23 +

weekday: 'EEE',

24 +

dayOfMonth: 'dd',

35 25

month: 'MMM',

36 -

year: 'YYYY',

26 +

year: 'yyyy',

37 27 38 28

decade: function decade(date: Date, culture: string, localizer: any) {

39 29

return localizer.format(date, 'YYYY', culture) + ' - ' + localizer.format(endOfDecade(date), 'YYYY', culture);

@@ -45,16 +35,24 @@ export function configure() {

45 35

},

46 36 47 37

firstOfWeek: function firstOfWeek(culture: string) {

48 -

return (moment.localeData(culture) as any).firstDayOfWeek();

38 +

var day = fistDay[culture?.tryAfter("-") ?? "ES"];

39 + 40 +

switch (day) {

41 +

case "sun": return 0;

42 +

case "mon": return 1;

43 +

case "fri": return 5;

44 +

case "sat": return 6;

45 +

default: throw new Error("Unexpected " + day);

46 +

}

49 47

},

50 48 51 49

parse: function parse(value: string, format: string, culture: string) {

52 50

if (value == undefined || value == "")

53 51

return undefined;

54 52 55 -

var moment = getMoment(culture, value, format);

56 -

if (moment.isValid())

57 -

return moment.toDate();

53 +

var t = DateTime.fromFormat(value, format ?? "F", { locale: culture })

54 +

if (t.isValid)

55 +

return t.toJSDate();

58 56 59 57

return undefined;

60 58

},

@@ -63,33 +61,165 @@ export function configure() {

63 61

if (value == undefined)

64 62

return "";

65 63 66 -

return getMoment(culture, value, undefined).format(_format);

64 +

return DateTime.fromJSDate(value, { locale: culture }).toFormat(_format);

67 65

}

68 66

};

69 67

(ReactWidgets as any).setDateLocalizer(localizer);

70 68 71 69

}

72 70 73 -

declare module "moment" {

74 - 75 -

interface Moment {

76 -

fromUserInterface(this: moment.Moment): moment.Moment;

77 -

toUserInterface(this: moment.Moment): moment.Moment;

78 -

}

71 +

//https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/weekData.json#L61

72 +

const fistDay: { [isoCode: string]: "mon" | "sat" | "sun" | "fri" } = {

73 +

"001": "mon",

74 +

"AD": "mon",

75 +

"AE": "sat",

76 +

"AF": "sat",

77 +

"AG": "sun",

78 +

"AI": "mon",

79 +

"AL": "mon",

80 +

"AM": "mon",

81 +

"AN": "mon",

82 +

"AR": "mon",

83 +

"AS": "sun",

84 +

"AT": "mon",

85 +

"AU": "sun",

86 +

"AX": "mon",

87 +

"AZ": "mon",

88 +

"BA": "mon",

89 +

"BD": "sun",

90 +

"BE": "mon",

91 +

"BG": "mon",

92 +

"BH": "sat",

93 +

"BM": "mon",

94 +

"BN": "mon",

95 +

"BR": "sun",

96 +

"BS": "sun",

97 +

"BT": "sun",

98 +

"BW": "sun",

99 +

"BY": "mon",

100 +

"BZ": "sun",

101 +

"CA": "sun",

102 +

"CH": "mon",

103 +

"CL": "mon",

104 +

"CM": "mon",

105 +

"CN": "sun",

106 +

"CO": "sun",

107 +

"CR": "mon",

108 +

"CY": "mon",

109 +

"CZ": "mon",

110 +

"DE": "mon",

111 +

"DJ": "sat",

112 +

"DK": "mon",

113 +

"DM": "sun",

114 +

"DO": "sun",

115 +

"DZ": "sat",

116 +

"EC": "mon",

117 +

"EE": "mon",

118 +

"EG": "sat",

119 +

"ES": "mon",

120 +

"ET": "sun",

121 +

"FI": "mon",

122 +

"FJ": "mon",

123 +

"FO": "mon",

124 +

"FR": "mon",

125 +

"GB": "mon",

126 +

"GB-alt-variant": "sun",

127 +

"GE": "mon",

128 +

"GF": "mon",

129 +

"GP": "mon",

130 +

"GR": "mon",

131 +

"GT": "sun",

132 +

"GU": "sun",

133 +

"HK": "sun",

134 +

"HN": "sun",

135 +

"HR": "mon",

136 +

"HU": "mon",

137 +

"ID": "sun",

138 +

"IE": "mon",

139 +

"IL": "sun",

140 +

"IN": "sun",

141 +

"IQ": "sat",

142 +

"IR": "sat",

143 +

"IS": "mon",

144 +

"IT": "mon",

145 +

"JM": "sun",

146 +

"JO": "sat",

147 +

"JP": "sun",

148 +

"KE": "sun",

149 +

"KG": "mon",

150 +

"KH": "sun",

151 +

"KR": "sun",

152 +

"KW": "sat",

153 +

"KZ": "mon",

154 +

"LA": "sun",

155 +

"LB": "mon",

156 +

"LI": "mon",

157 +

"LK": "mon",

158 +

"LT": "mon",

159 +

"LU": "mon",

160 +

"LV": "mon",

161 +

"LY": "sat",

162 +

"MC": "mon",

163 +

"MD": "mon",

164 +

"ME": "mon",

165 +

"MH": "sun",

166 +

"MK": "mon",

167 +

"MM": "sun",

168 +

"MN": "mon",

169 +

"MO": "sun",

170 +

"MQ": "mon",

171 +

"MT": "sun",

172 +

"MV": "fri",

173 +

"MX": "sun",

174 +

"MY": "mon",

175 +

"MZ": "sun",

176 +

"NI": "sun",

177 +

"NL": "mon",

178 +

"NO": "mon",

179 +

"NP": "sun",

180 +

"NZ": "mon",

181 +

"OM": "sat",

182 +

"PA": "sun",

183 +

"PE": "sun",

184 +

"PH": "sun",

185 +

"PK": "sun",

186 +

"PL": "mon",

187 +

"PR": "sun",

188 +

"PT": "sun",

189 +

"PY": "sun",

190 +

"QA": "sat",

191 +

"RE": "mon",

192 +

"RO": "mon",

193 +

"RS": "mon",

194 +

"RU": "mon",

195 +

"SA": "sun",

196 +

"SD": "sat",

197 +

"SE": "mon",

198 +

"SG": "sun",

199 +

"SI": "mon",

200 +

"SK": "mon",

201 +

"SM": "mon",

202 +

"SV": "sun",

203 +

"SY": "sat",

204 +

"TH": "sun",

205 +

"TJ": "mon",

206 +

"TM": "mon",

207 +

"TR": "mon",

208 +

"TT": "sun",

209 +

"TW": "sun",

210 +

"UA": "mon",

211 +

"UM": "sun",

212 +

"US": "sun",

213 +

"UY": "mon",

214 +

"UZ": "mon",

215 +

"VA": "mon",

216 +

"VE": "sun",

217 +

"VI": "sun",

218 +

"VN": "mon",

219 +

"WS": "sun",

220 +

"XK": "mon",

221 +

"YE": "sun",

222 +

"ZA": "sun",

223 +

"ZW": "sun"

224 +

};

79 225 80 -

function smartNow(this: moment.Moment): moment.Moment;

81 -

}

82 - 83 -

export function asumeGlobalUtcMode(m: typeof moment, utcMode: boolean) {

84 -

if (utcMode) {

85 -

m.fn.fromUserInterface = function (this: moment.Moment) { return this.utc(); };

86 -

m.fn.toUserInterface = function (this: moment.Moment) { return this.local(); };

87 -

m.smartNow = function () { return moment.utc(); };

88 -

}

89 - 90 -

else {

91 -

m.fn.fromUserInterface = function (this: moment.Moment) { return this; };

92 -

m.fn.toUserInterface = function (this: moment.Moment) { return this; };

93 -

m.smartNow = function () { return moment(); };

94 -

}

95 -

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4