Exemplo n.º 1
0
gXAxis::gXAxis(QColor col,bool fadeout)
:Layer(NoChannel)
{
    m_line_color=col;
    m_text_color=col;
    m_major_color=Qt::darkGray;
    m_minor_color=Qt::lightGray;
    m_show_major_lines=false;
    m_show_minor_lines=false;
    m_show_minor_ticks=true;
    m_show_major_ticks=true;
    m_utcfix=false;
    m_fadeout=fadeout;
    m_textureID=0;
//    QDateTime d=QDateTime::currentDateTime();
//    QTime t1=d.time();
//    QTime t2=d.toUTC().time();

//    tz_offset=t2.secsTo(t1);
//    tz_hours=tz_offset/3600.0;
//    tz_offset*=1000L;

    tz_offset=timezoneOffset();
    tz_hours=tz_offset/3600000.0;
}
void InstagramClient::updateTimeline(QString maxID, QJSValue callback)
{
    qDebug() << "Update timeline...";

    QUrlQuery q;
    q.addQueryItem("phone_id", phoneID());
    q.addQueryItem("timezone_offset", QString::number(timezoneOffset()));

    if (!maxID.isEmpty())
        q.addQueryItem("max_id", maxID);

    QUrl url("https://i.instagram.com/api/v1/feed/timeline/");
    url.setQuery(q);

    executeGetRequest(url, callback);
}
Exemplo n.º 3
0
/*****************************************************************************
*
* parse8601Time -
*
* This is common code for Duration and Throttling (at least).
*
* Based in http://stackoverflow.com/questions/26895428/how-do-i-parse-an-iso-8601-date-with-optional-milliseconds-to-a-struct-tm-in-c
*
*/
int64_t parse8601Time(const std::string& ss)
{
  int    y = 0;
  int    M = 0;
  int    d = 0;
  int    h = 0;
  int    m = 0;
  float  s = 0;
  char   tz[10];

  // Length check, to avoid buffer overflow in tz[]. Calculation is as follows:
  //
  //  5 (year with "-") + 3 * 2 (day and month with "-" or "T")
  //  3 * 3 (hour/minute/second with ":" or ".") + 3 (miliseconds) + 6 (worst case timezone: "+01:00" = 29
  if (ss.length() > 29)
  {
    return -1;
  }

  // According to https://en.wikipedia.org/wiki/ISO_8601#Times, the following formats have to be supported
  //
  // hh:mm:ss.sss or  hhmmss.sss
  // hh:mm:ss     or  hhmmss
  // hh:mm        or  hhmm
  // hh
  //
  // With regards the first case (hh:mm:ss.sss or hhmmss.sss) note that by the way sscanf() works for the %f
  // formater, this will work not only with .000, but also with .0, .00, .0000, etc. This is fine with ISO8601
  // which states that "There is no limit on the number of decimal places for the decimal fraction".

  // Default timezone is Z, sscanf will override it if an explicit timezone is provided
  snprintf(tz, sizeof(tz), "%s", "Z");

  bool validDate = ((sscanf(ss.c_str(), "%4d-%2d-%2dT%2d:%2d:%f%s", &y, &M, &d, &h, &m, &s, tz) >= 6)  ||  // Trying hh:mm:ss.sss or hh:mm:ss
                    (sscanf(ss.c_str(), "%4d-%2d-%2dT%2d%2d%f%s", &y, &M, &d, &h, &m, &s, tz) >= 6)    ||  // Trying hhmmss.sss or hhmmss
                    (sscanf(ss.c_str(), "%4d-%2d-%2dT%2d:%2d%s", &y, &M, &d, &h, &m, tz) >= 5)         ||  // Trying hh:mm
                    (sscanf(ss.c_str(), "%4d-%2d-%2dT%2d%2d%s", &y, &M, &d, &h, &m, tz) >= 5)          ||  // Trying hhmm
                    (sscanf(ss.c_str(), "%4d-%2d-%2dT%2d%s", &y, &M, &d, &h, tz) >= 4)                 ||  // Trying hh
                    (sscanf(ss.c_str(), "%4d-%2d-%2d%s", &y, &M, &d, tz) == 3));                           // Trying just date (in this case tz is not allowed)

  if (!validDate)
  {
    return -1;
  }

  int offset = timezoneOffset(tz);
  if (offset == -1)
  {
    return -1;
  }

  // Note that at the present moment we are not doing anything with milliseconds, but
  // in the future we could use that to increase time resolution (however, not as part
  // of the tm struct)

  struct tm time;
  time.tm_year = y - 1900; // Year since 1900
  time.tm_mon  = M - 1;    // 0-11
  time.tm_mday = d;        // 1-31
  time.tm_hour = h;        // 0-23
  time.tm_min  = m;        // 0-59
  time.tm_sec  = (int)s;   // 0-61 (0-60 in C++11)

  return (int64_t) (timegm(&time) - offset);
}