Today, the concept of JIT production has usage in production management and inventory control widely. In such an environment, tardiness or earliness is essential. Therefore, scheduling tries to minimize the sum of earliness and tardiness, which represents customer satisfaction, as well as inventory control. Most studies in scheduling adopt the assumption that machines are continuously available during the planning horizon. But in the real world, some machines may be temporarily unavailable for reasons such as breakdowns or preventive maintenance activities. So, considering the unavailability as a constraint is necessary for scheduling problems in the JIT production system. In this study, the unavailability constraint has been investigated with two flexible modes on a single machine. In each period, the duration of unavailability corresponding to the continuous working time of the machine changes in a discrete manner and can adopt two different values. Since the objective function is irregular, unforced idleness may be useful, increasing the complexity of the problem. First, a binary integer mathematical programming model is presented. Due to the NP-Hardness of the problem under consideration, a genetic algorithm is proposed to solve the problem in large dimensions. To examine the performance of the Genetic Algorithm (GA) and Particle Swarm Optimization (PSO), several problem instances are generated and solved, and the obtained results are compared with those obtained from solving the mathematical model with the GAMS software. The computational results indicate the proposed algorithm has a good performance with an average deviation of 0.87% and a reasonable computational time.