~pythoneers/ubuntu/lucid/python2.6/ltsppa

« back to all changes in this revision

Viewing changes to Modules/datetimemodule.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100311133019-sonignhpjsu6ld0x
Tags: 2.6.5~rc2-0ubuntu1
Python 2.6.5 release candidate 2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1362
1362
        x = PyOS_snprintf(buffer, bufflen,
1363
1363
                          "%04d-%02d-%02d",
1364
1364
                          GET_YEAR(dt), GET_MONTH(dt), GET_DAY(dt));
 
1365
        assert(bufflen >= x);
1365
1366
        return buffer + x;
1366
1367
}
1367
1368
 
1368
 
static void
 
1369
static char *
1369
1370
isoformat_time(PyDateTime_DateTime *dt, char buffer[], int bufflen)
1370
1371
{
 
1372
        int x;
1371
1373
        int us = DATE_GET_MICROSECOND(dt);
1372
1374
 
1373
 
        PyOS_snprintf(buffer, bufflen,
1374
 
                      "%02d:%02d:%02d", /* 8 characters */
1375
 
                      DATE_GET_HOUR(dt),
1376
 
                      DATE_GET_MINUTE(dt),
1377
 
                      DATE_GET_SECOND(dt));
 
1375
        x = PyOS_snprintf(buffer, bufflen,
 
1376
                          "%02d:%02d:%02d",
 
1377
                          DATE_GET_HOUR(dt),
 
1378
                          DATE_GET_MINUTE(dt),
 
1379
                          DATE_GET_SECOND(dt));
 
1380
        assert(bufflen >= x);
1378
1381
        if (us)
1379
 
                PyOS_snprintf(buffer + 8, bufflen - 8, ".%06d", us);
 
1382
                x += PyOS_snprintf(buffer + x, bufflen - x, ".%06d", us);
 
1383
        assert(bufflen >= x);
 
1384
        return buffer + x;
1380
1385
}
1381
1386
 
1382
1387
/* ---------------------------------------------------------------------------
4200
4205
        cp = isoformat_date((PyDateTime_Date *)self, buffer, sizeof(buffer));
4201
4206
        assert(cp != NULL);
4202
4207
        *cp++ = sep;
4203
 
        isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
4204
 
        result = PyString_FromString(buffer);
 
4208
        cp = isoformat_time(self, cp, sizeof(buffer) - (cp - buffer));
 
4209
        result = PyString_FromStringAndSize(buffer, cp - buffer);
4205
4210
        if (result == NULL || ! HASTZINFO(self))
4206
4211
                return result;
4207
4212