From 138cdb03585a486f4cfa1cb79547995a8a540258 Mon Sep 17 00:00:00 2001 From: Shuichi Ohsawa Date: Mon, 14 Nov 2016 12:18:18 +0900 Subject: [PATCH] Fixed a bug that does not start or stop at 0 o'clock. --- code/ec2-scheduler.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code/ec2-scheduler.py b/code/ec2-scheduler.py index 4f364fb..d29e5ea 100644 --- a/code/ec2-scheduler.py +++ b/code/ec2-scheduler.py @@ -15,6 +15,7 @@ import boto3 import datetime import json +import re from urllib2 import Request from collections import Counter @@ -158,6 +159,13 @@ def lambda_handler(event, context): if d.lower() == nowDay: isActiveDay = True + # Slice 24 hours + if re.match(r"^23[0-9]{2}$", nowMax) and \ + re.match(r"^00[0-9]{2}$", now) and \ + re.match(r"^00[0-9]{2}$", startTime): + startTime = "24" + startTime[2:] + now = "24" + now[2:] + # Append to start list if startTime >= str(nowMax) and startTime <= str(now) and \ isActiveDay == True and state == "stopped":