Format a date or datetime object as a pair of (date, time) strings in the format required by the NEWNEWS and NEWGROUPS commands. If a date object is passed, the time is assumed to be midnight (00h00). The returned representation depends on the legacy flag: * if legacy is False
(dt, legacy=False)
| 255 | return datetime.datetime(year, month, day, hours, minutes, seconds) |
| 256 | |
| 257 | def _unparse_datetime(dt, legacy=False): |
| 258 | """Format a date or datetime object as a pair of (date, time) strings |
| 259 | in the format required by the NEWNEWS and NEWGROUPS commands. If a |
| 260 | date object is passed, the time is assumed to be midnight (00h00). |
| 261 | |
| 262 | The returned representation depends on the legacy flag: |
| 263 | * if legacy is False (the default): |
| 264 | date has the YYYYMMDD format and time the HHMMSS format |
| 265 | * if legacy is True: |
| 266 | date has the YYMMDD format and time the HHMMSS format. |
| 267 | RFC 3977 compliant servers should understand both formats; therefore, |
| 268 | legacy is only needed when talking to old servers. |
| 269 | """ |
| 270 | if not isinstance(dt, datetime.datetime): |
| 271 | time_str = "000000" |
| 272 | else: |
| 273 | time_str = "{0.hour:02d}{0.minute:02d}{0.second:02d}".format(dt) |
| 274 | y = dt.year |
| 275 | if legacy: |
| 276 | y = y % 100 |
| 277 | date_str = "{0:02d}{1.month:02d}{1.day:02d}".format(y, dt) |
| 278 | else: |
| 279 | date_str = "{0:04d}{1.month:02d}{1.day:02d}".format(y, dt) |
| 280 | return date_str, time_str |
| 281 | |
| 282 | |
| 283 | if _have_ssl: |