#include <NTPClient.h>
#include <WiFiUdp.h>



// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "tik.cesnet.cz");

//Week Days
String weekDays[7]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
 
//Month names
String months[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
 

void time_client_setup() {
  // Initialize a NTPClient to get time
  timeClient.begin();
  // Set offset time in seconds to adjust for your timezone, for example:
  // GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
  timeClient.setTimeOffset(2*3600);
}

void time_client_update() {
  timeClient.update();
}

unsigned long time_getEpochTime() {
  return timeClient.getEpochTime();
}

String time_getFormattedTime(){
  return timeClient.getFormattedTime();
}

int time_getHours() {
  return timeClient.getHours();
}

int time_getMinutes() {
  return timeClient.getMinutes();
}

int time_getSeconds() {
  return timeClient.getSeconds();
}

String time_getDayName(){
  return weekDays[timeClient.getDay()];
}

int time_getDay(){
  unsigned long epochTime = time_getEpochTime();
  struct tm *ptm = gmtime ((time_t *)&epochTime); 
  return ptm->tm_mday;
}

int time_getMonth(){
  unsigned long epochTime = time_getEpochTime();
  struct tm *ptm = gmtime ((time_t *)&epochTime); 
  return ptm->tm_mon+1;
}

int time_getYear(){
  unsigned long epochTime = time_getEpochTime();
  struct tm *ptm = gmtime ((time_t *)&epochTime); 
  return ptm->tm_year+1900;
}

String time_getMonthName(){
  return months[time_getMonth()-1];
}

