@@ -261,3 +261,70 @@ func DateReformat(dt1 string, currentFormat, newFormat string) string {
261
261
262
262
return ""
263
263
}
264
+
265
+ type DateStrCheck uint8
266
+
267
+ const (
268
+ DateStrCheckOk DateStrCheck = 0
269
+ DateStrCheckErrInvalid DateStrCheck = 1
270
+ DateStrCheckErrOutOfRange DateStrCheck = 2
271
+ DateStrCheckErrEmpty DateStrCheck = 3
272
+ )
273
+
274
+ // DateStrCheckAge checks a date string considering minimum and maximum age
275
+ // The resulting code can be translated to text, according prefered idiom, with DateStrCheckErrMessage
276
+ func DateStrCheckAge (date , format string , yearsAgeMin , yearsAgeMax int , acceptEmpty bool ) DateStrCheck {
277
+ if date == "" {
278
+ if ! acceptEmpty {
279
+ return DateStrCheckErrEmpty
280
+ }
281
+
282
+ return DateStrCheckOk
283
+ }
284
+
285
+ dt := StringAsDateTime (date , format )
286
+
287
+ if dt .IsZero () {
288
+ return DateStrCheckErrInvalid
289
+ }
290
+
291
+ yearsAge := YearsAge (dt )
292
+
293
+ if ! Between (yearsAge , yearsAgeMin , yearsAgeMax ) {
294
+ return DateStrCheckErrOutOfRange
295
+ }
296
+
297
+ return DateStrCheckOk
298
+ }
299
+
300
+ // DateStrCheckRange checks a date string considering minimum and maximum date range
301
+ // The resulting code can be translated to text, according prefered idiom, with DateStrCheckErrMessage
302
+ func DateStrCheckRange (date , format string , dateMin , dateMax time.Time , acceptEmpty bool ) DateStrCheck {
303
+ if date == "" {
304
+ if ! acceptEmpty {
305
+ return DateStrCheckErrEmpty
306
+ }
307
+
308
+ return DateStrCheckOk
309
+ }
310
+
311
+ dt := StringAsDateTime (date , format )
312
+
313
+ if dt .IsZero () {
314
+ return DateStrCheckErrInvalid
315
+ }
316
+
317
+ if ! dateMin .IsZero () {
318
+ if dt .Before (dateMin ) {
319
+ return DateStrCheckErrOutOfRange
320
+ }
321
+ }
322
+
323
+ if ! dateMax .IsZero () {
324
+ if dt .After (dateMax ) {
325
+ return DateStrCheckErrOutOfRange
326
+ }
327
+ }
328
+
329
+ return DateStrCheckOk
330
+ }
0 commit comments