Code Duplication    Length = 30-36 lines in 2 locations

src/ocrd_models/ocrd_page_generateds.py 2 locations

@@ 383-418 (lines=36) @@
380
        return values
381
    def gds_validate_datetime(self, input_data, node=None, input_name=''):
382
        return input_data
383
    def gds_format_datetime(self, input_data, input_name=''):
384
        if input_data.microsecond == 0:
385
            _svalue = '%04d-%02d-%02dT%02d:%02d:%02d' % (
386
                input_data.year,
387
                input_data.month,
388
                input_data.day,
389
                input_data.hour,
390
                input_data.minute,
391
                input_data.second,
392
            )
393
        else:
394
            _svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % (
395
                input_data.year,
396
                input_data.month,
397
                input_data.day,
398
                input_data.hour,
399
                input_data.minute,
400
                input_data.second,
401
                ('%f' % (float(input_data.microsecond) / 1000000))[2:],
402
            )
403
        if input_data.tzinfo is not None:
404
            tzoff = input_data.tzinfo.utcoffset(input_data)
405
            if tzoff is not None:
406
                total_seconds = tzoff.seconds + (86400 * tzoff.days)
407
                if total_seconds == 0:
408
                    _svalue += 'Z'
409
                else:
410
                    if total_seconds < 0:
411
                        _svalue += '-'
412
                        total_seconds *= -1
413
                    else:
414
                        _svalue += '+'
415
                    hours = total_seconds // 3600
416
                    minutes = (total_seconds - (hours * 3600)) // 60
417
                    _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
418
        return _svalue
419
    @classmethod
420
    def gds_parse_datetime(cls, input_data):
421
        tz = None
@@ 496-525 (lines=30) @@
493
        return dt.date()
494
    def gds_validate_time(self, input_data, node=None, input_name=''):
495
        return input_data
496
    def gds_format_time(self, input_data, input_name=''):
497
        if input_data.microsecond == 0:
498
            _svalue = '%02d:%02d:%02d' % (
499
                input_data.hour,
500
                input_data.minute,
501
                input_data.second,
502
            )
503
        else:
504
            _svalue = '%02d:%02d:%02d.%s' % (
505
                input_data.hour,
506
                input_data.minute,
507
                input_data.second,
508
                ('%f' % (float(input_data.microsecond) / 1000000))[2:],
509
            )
510
        if input_data.tzinfo is not None:
511
            tzoff = input_data.tzinfo.utcoffset(input_data)
512
            if tzoff is not None:
513
                total_seconds = tzoff.seconds + (86400 * tzoff.days)
514
                if total_seconds == 0:
515
                    _svalue += 'Z'
516
                else:
517
                    if total_seconds < 0:
518
                        _svalue += '-'
519
                        total_seconds *= -1
520
                    else:
521
                        _svalue += '+'
522
                    hours = total_seconds // 3600
523
                    minutes = (total_seconds - (hours * 3600)) // 60
524
                    _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
525
        return _svalue
526
    def gds_validate_simple_patterns(self, patterns, target):
527
        # pat is a list of lists of strings/patterns.
528
        # The target value must match at least one of the patterns