@ejfdelgado/ejflab-common 1.12.3 → 1.13.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/MyDates.js +53 -11
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-common",
3
3
  "type": "commonjs",
4
- "version": "1.12.3",
4
+ "version": "1.13.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/ejfdelgado/ejflab-common.git"
package/src/MyDates.js CHANGED
@@ -136,44 +136,86 @@ class MyDates {
136
136
  deadline: (mananaInicio.getTime() - hoy.getTime()),
137
137
  };
138
138
  }
139
+ // MyDates.getDefaults(args)
140
+ static getDefaults(args, currentYear, nextYears, myDefault = "") {
141
+ console.log(JSON.stringify(args, null, 4));
142
+ if (args instanceof Array) {
143
+ if (args.lenght == 1) {
144
+ currentYear = args[0];
145
+ nextYears = args[0];
146
+ } else if (args.lenght == 2) {
147
+ currentYear = args[0];
148
+ nextYears = args[1];
149
+ }
150
+ if (args.lenght >= 3) {
151
+ myDefault = args[2];
152
+ }
153
+ }
154
+ return {
155
+ currentYear,
156
+ nextYears,
157
+ myDefault
158
+ };
159
+ }
160
+
139
161
  static formatDateBasic(dateformat, now, ...args) {
162
+ const {
163
+ currentYear,
164
+ nextYears,
165
+ myDefault
166
+ } = MyDates.getDefaults(args, "opcion2", "opcion1", "Día / Mes / Año");
140
167
  if (now instanceof Date) {
141
168
  if (new Date().getFullYear() == now.getFullYear()) {
142
- return dateformat(now, "opcion2");
169
+ return dateformat(now, currentYear);
143
170
  } else {
144
- return dateformat(now, "opcion1");
171
+ return dateformat(now, nextYears);
145
172
  }
146
173
  } else {
147
- return "Día / Mes / Año";
174
+ return myDefault;
148
175
  }
149
176
  }
150
177
  static formatDateSimpleBasic(dateformat, now, ...args) {
178
+ const {
179
+ currentYear,
180
+ nextYears,
181
+ myDefault
182
+ } = MyDates.getDefaults(args, "simple2", "simple1", "Día / Mes / Año");
151
183
  if (now instanceof Date) {
152
184
  if (new Date().getFullYear() == now.getFullYear()) {
153
- return dateformat(now, "simple2");
185
+ return dateformat(now, currentYear);
154
186
  } else {
155
- return dateformat(now, "simple1");
187
+ return dateformat(now, nextYears);
156
188
  }
157
189
  } else {
158
- return "Día / Mes / Año";
190
+ return myDefault;
159
191
  }
160
192
  }
161
193
  static formatDateCompletoBasic(dateformat, now, ...args) {
194
+ const {
195
+ currentYear,
196
+ nextYears,
197
+ myDefault
198
+ } = MyDates.getDefaults(args, "completo2", "completo1", "Día / Mes / Año Hora:Minutos:Segundos");
162
199
  if (now instanceof Date) {
163
200
  if (new Date().getFullYear() == now.getFullYear()) {
164
- return dateformat(now, "completo2");
201
+ return dateformat(now, currentYear);
165
202
  } else {
166
- return dateformat(now, "completo1");
203
+ return dateformat(now, nextYears);
167
204
  }
168
205
  } else {
169
- return "Día / Mes / Año Hora:Minutos:Segundos";
206
+ return myDefault;
170
207
  }
171
208
  }
172
209
  static formatTimeBasic(dateformat, now, ...args) {
210
+ const {
211
+ currentYear,
212
+ nextYears,
213
+ myDefault
214
+ } = MyDates.getDefaults(args, "opcion3", "opcion3", "Hora / Minuto");
173
215
  if (now instanceof Date) {
174
- return dateformat(now, "opcion3");
216
+ return dateformat(now, currentYear);
175
217
  } else {
176
- return "Hora / Minuto";
218
+ return myDefault;
177
219
  }
178
220
  }
179
221
  static formatPayu(dateformat, now) {