Help with my code

This is my first project, and I need some help. If it’s past 8:00 PM, everything works, the door locks and the LED turns on. If it is between 6:00 AM, and 8:00 PM, the door simply locks with the LED off and will not respond. It appears that everything works except my last if statement ( if ((time == 0)…). I thought maybe I nested my if statements incorrectly, but I don’t believe that is the case. I then thought maybe my photo resistor was bad, but I tested it with some other code, and verified through serial monitor, and it works fine. Any thoughts are appreciated.

#include <Time.h> //call time library
#include <Servo.h> //call servo library

const int LED = 13; // set pin for LED
const int SENSOR = 0; // set input pin for photo resistor (analog pins are always input)
int val = 0; // variable to store the value coming from the sensor
int time = 0; // variable to store day or night (day = 0, night =1)
int old_time = 0; // variable to store the previous time value
int photo = 0; // variable to store the amount of light (dark =1, light =0)
int old_photo = 0; // variable to store the previous light value
int codestart = 0; // variable to identify code startup (0 = start)
Servo myservo; // create servo object to control a servo (lock = 100, unlock = 45)

void setup() {

pinMode (LED, OUTPUT); // tell Arduino LED (Pin #13) is output
myservo.attach(9); // attaches the servo on pin 9 to the servo object
setTime(19,59,40,2,10,13); // sets time to hh,mm,ss,DD,MM,YY
}

void loop(){

val = analogRead(SENSOR); // read the value from the sensor

if (val < 20) { // if dark outside
photo = 1; // dark
} else {
photo = 0; // light
delay(500);
}

if ((hour() >= 20) || (hour() < 6)) { // if >= 8:00 PM or < 6:00 AM
time = 1; // night
} else {
time = 0; //day
delay(500);
}

if (codestart == 0) { // if this is the first time the code has run
old_photo = 1 - photo;
old_time = 1 - time;
codestart = 1; // indicate code has run previously
delay(500);
}

if ((time == 1) && (old_time == 0)) { // if night, and use to be day
myservo.write(100); // tell servo to go lock
digitalWrite (LED, HIGH); // turn LED on
old_time = time;
delay(500);
}

if ((time == 0) && (old_time == 1)) { // if day, and use to be night
old_time = time;
delay(500);
if ((photo = 1) && (old_photo = 0)) { // if dark, and use to be light
myservo.write(100); // tell servo to lock
digitalWrite (LED, HIGH); // turn LED on
old_photo = photo;
delay(500);
} else if ((photo == 0) && (old_photo == 1)) { // if light, and use to be dark
myservo.write(45); // tell servo to unlock
digitalWrite (LED, LOW); // turn LED off
old_photo = photo;
}
}
}

SerialServoLedTime3.pdf (15.9 KB)

    if ((photo = 1) && (old_photo = 0)) { // if dark, and use to be light

Wow, that did it. How very cool to have such helpful forum repliers. Thank you so much.