Guest User

Untitled

a guest
Jan 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. int diferencia_entre_fechas(std::string fecha1, std::string fecha2)
  2. {
  3. //Retorna en segundos la diferencia entre dos fechas dadas
  4. tm fecha_menor, fecha_mayor;
  5. time_t epoca1, epoca2;
  6.  
  7. strptime(fecha1.c_str(), "%Y-%m-%d %H:%M:%S", &fecha_menor);
  8. strptime(fecha2.c_str(), "%Y-%m-%d %H:%M:%S", &fecha_mayor);
  9.  
  10. //Esto hace lo mismo que las 2 lineas de arriba
  11. //std::istringstream fmenor(fecha1);
  12. //std::istringstream fmayor(fecha2);
  13. //fmenor >> std::get_time(&fecha_menor, "%Y-%m-%d %H:%M:%S");
  14. //fmayor >> std::get_time(&fecha_mayor, "%Y-%m-%d %H:%M:%S");
  15.  
  16. epoca1 = mktime(&fecha_menor);
  17. epoca2 = mktime(&fecha_mayor);
  18.  
  19. //std::cout << fecha_menor.tm_mday << "-" << fecha_menor.tm_mon << "-" << fecha_menor.tm_year << " " <<fecha_menor.tm_hour << ":" << fecha_menor.tm_min << ":" << fecha_menor.tm_sec << "n";
  20. //std::cout << fecha_mayor.tm_mday << "-" << fecha_mayor.tm_mon << "-" << fecha_mayor.tm_year << " " <<fecha_mayor.tm_hour << ":" << fecha_mayor.tm_min << ":" << fecha_mayor.tm_sec << "n";
  21.  
  22. //std::cout << "tm 1: " << asctime(&fecha_menor) << "n";
  23. //std::cout << "tm 2: " << asctime(&fecha_mayor) << "n";
  24.  
  25. std::cout << "diferencia: " << difftime(epoca2, epoca1) << "n";
  26.  
  27. return difftime(epoca2, epoca1);
  28. }
  29.  
  30. Glib::signal_timeout().connect(sigc::mem_fun(*this, &Ventana::actualizar_tiempo), 1000);
  31.  
  32. bool Ventana::actualizar_tiempo()
  33. {
  34. if(tiempo < 0)
  35. controlador->entrar_y_salir();
  36. }
  37.  
  38. //Este es otro archivo
  39. void Controlar::entrar_y_salir()
  40. {
  41. //Funcion para iniciar y detener el contador de tiempo
  42. std::string hora_entrada = "2019-01-18 11:32:00";
  43. std::string hora_salida = "2019-01-18 11:32:04";
  44. int tiempo = diferencia_entre_fechas(hora_entrada, hora_salida);
  45. ....
  46. }
Add Comment
Please, Sign In to add comment