From 33aff43ff6e9cec882ffecc11bf761798a06f274 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Wed, 27 Jan 2016 14:27:12 +0000 Subject: [PATCH] Added a tiny script to disambiguate document timestamps. - Legacy-Id: 10752 --- ietf/bin/fix-ambiguous-document-timestamps | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 ietf/bin/fix-ambiguous-document-timestamps diff --git a/ietf/bin/fix-ambiguous-document-timestamps b/ietf/bin/fix-ambiguous-document-timestamps new file mode 100755 index 000000000..1a683c5a6 --- /dev/null +++ b/ietf/bin/fix-ambiguous-document-timestamps @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# -*- Python -*- + +""" +This script looks at document timestamps going back one year, and if it finds +ambiguous timestamps, shifts them backwards one hour in order to disambiguate +them. +""" + +import os, sys +import datetime +import pytz + +filename = os.path.abspath(__file__) +basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) +sys.path = [ basedir ] + sys.path +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings") + +import django +django.setup() + +from django.conf import settings +from ietf.doc.models import Document + +now = datetime.datetime.now() +then = now - datetime.timedelta(days=365) + +for d in Document.objects.filter(time__gt=then).order_by('-time'): + tz = pytz.timezone(settings.TIME_ZONE) + try: + t = tz.localize(d.time, is_dst=None) + except pytz.AmbiguousTimeError as e: + orig = d.time + d.time = d.time - datetime.timedelta(minutes=60) + print "%s: changed %s --> %s" % (d.name, orig, d.time) + d.save()