format method

String format()

Return ISO8601 String of format YYYY-MM-DDThh:mm:ss.sss+hh:mm:ss

Implementation

String format() {
  var buffer = StringBuffer();

  // DateTime with millisecond/microsecond leads to variable length ISO String
  DateTime simpleDateTime = DateTime(_dateTime.year, _dateTime.month,
      _dateTime.day, _dateTime.hour, _dateTime.minute, _dateTime.second);
  String isoString = simpleDateTime.toIso8601String();
  buffer.write(isoString.substring(0, isoString.length - 4));

  int totalMicroseconds = _nanoseconds + Temporal.getNanoseconds(_dateTime);
  // ensure DateTime strings stored in SQLite to be in the same format
  // and string based DataTime comparison to be accurate
  buffer.write('.${totalMicroseconds.toString().padLeft(9, '0')}');

  if (_offset != null) {
    if (_offset!.inSeconds == 0) {
      buffer.write('Z');
    } else {
      buffer.write(Temporal.durationToOffset(_offset!));
    }
  }

  return buffer.toString();
}