# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2020-02-26 07:38
from __future__ import unicode_literals
from datetime import datetime
from timezonefinder import TimezoneFinder
import pytz

from django.db import migrations
from django.utils import timezone


tf = TimezoneFinder()


def set_timezone(apps, schema_editor):
    Event = apps.get_model('events', 'Event')

    for event in Event.objects.filter(start__isnull=False, location__isnull=False):
        tz_name = tf.timezone_at(
            lng=event.location.position.x,
            lat=event.location.position.y
        )
        tz = pytz.timezone(tz_name)
        start = event.start.astimezone(timezone.get_current_timezone())

        event.start = tz.localize(
            datetime(
                start.year,
                start.month,
                start.day,
                start.hour,
                start.minute,
            )
        )
        event.save()


class Migration(migrations.Migration):

    dependencies = [
        ('events', '0014_auto_20200217_1107'),
    ]

    operations = [
        migrations.RunPython(set_timezone)
    ]

Add migration to set start time to local timzeone
Add migration to set start time to local timzeone
