Skip to content

Commit 33aff43

Browse files
committed
Added a tiny script to disambiguate document timestamps.
- Legacy-Id: 10752
1 parent 8e399de commit 33aff43

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
# -*- Python -*-
3+
4+
"""
5+
This script looks at document timestamps going back one year, and if it finds
6+
ambiguous timestamps, shifts them backwards one hour in order to disambiguate
7+
them.
8+
"""
9+
10+
import os, sys
11+
import datetime
12+
import pytz
13+
14+
filename = os.path.abspath(__file__)
15+
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
16+
sys.path = [ basedir ] + sys.path
17+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ietf.settings")
18+
19+
import django
20+
django.setup()
21+
22+
from django.conf import settings
23+
from ietf.doc.models import Document
24+
25+
now = datetime.datetime.now()
26+
then = now - datetime.timedelta(days=365)
27+
28+
for d in Document.objects.filter(time__gt=then).order_by('-time'):
29+
tz = pytz.timezone(settings.TIME_ZONE)
30+
try:
31+
t = tz.localize(d.time, is_dst=None)
32+
except pytz.AmbiguousTimeError as e:
33+
orig = d.time
34+
d.time = d.time - datetime.timedelta(minutes=60)
35+
print "%s: changed %s --> %s" % (d.name, orig, d.time)
36+
d.save()

0 commit comments

Comments
 (0)