[PHP-BUG] Req #62911 [NEW]: Add DateTime::__toString()

2012-08-23 Thread bdurand-php at ssji dot net
From: bdurand-php at ssji dot net
Operating system: 
PHP version:  Irrelevant
Package:  Date/time related
Bug Type: Feature/Change Request
Bug description:Add DateTime::__toString()

Description:

Hello,

I want to have a default behavior to convert an instance of the class
DateTime into a string. I mean implement the method __toString() in the
DateTime class.

The default format should be ISO8601 IMHO, but we can add an attribut to
define the default format to use for __toString() and format() method.

Greetings.

Test script:
---
https://bugs.php.net/bug.php?id=62911&edit=1
-- 
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62911&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62911&r=trysnapshot53
Try a snapshot (trunk):  
https://bugs.php.net/fix.php?id=62911&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62911&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62911&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62911&r=alreadyfixed
Need backtrace:  
https://bugs.php.net/fix.php?id=62911&r=needtrace
Need Reproduce Script:   
https://bugs.php.net/fix.php?id=62911&r=needscript
Try newer version:   
https://bugs.php.net/fix.php?id=62911&r=oldversion
Not developer issue: 
https://bugs.php.net/fix.php?id=62911&r=support
Expected behavior:   
https://bugs.php.net/fix.php?id=62911&r=notwrong
Not enough info: 
https://bugs.php.net/fix.php?id=62911&r=notenoughinfo
Submitted twice: 
https://bugs.php.net/fix.php?id=62911&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62911&r=globals
PHP 4 support discontinued:  
https://bugs.php.net/fix.php?id=62911&r=php4
Daylight Savings:https://bugs.php.net/fix.php?id=62911&r=dst
IIS Stability:   
https://bugs.php.net/fix.php?id=62911&r=isapi
Install GNU Sed: 
https://bugs.php.net/fix.php?id=62911&r=gnused
Floating point limitations:  
https://bugs.php.net/fix.php?id=62911&r=float
No Zend Extensions:  
https://bugs.php.net/fix.php?id=62911&r=nozend
MySQL Configuration Error:   
https://bugs.php.net/fix.php?id=62911&r=mysqlcfg



Req #62911 [Wfx]: Add DateTime::__toString()

2012-08-27 Thread bdurand-php at ssji dot net
Edit report at https://bugs.php.net/bug.php?id=62911&edit=1

 ID: 62911
 User updated by:bdurand-php at ssji dot net
 Reported by:bdurand-php at ssji dot net
 Summary:Add DateTime::__toString()
 Status: Wont fix
 Type:   Feature/Change Request
 Package:Date/time related
 PHP Version:Irrelevant
 Assigned To:willfitch
 Block user comment: N
 Private report: N

 New Comment:

The timezone can be defined in the constructor, with the directive tz php.ini, 
or with date_default_timezone_get() function.

A DateTime is a string in fact, so it's logic to have a string cast available. 
Which format is more standard than ISO format? Another common format is the 
timestamp, but it can not represent all dates.
Other languages did this behavior ​​like python. Why PHP can't?

I know that I can subclass any (core) class... it's not the problem here.


Previous Comments:

[2012-08-27 15:24:45] willfi...@php.net

Would it be worth investing time in adding a setter/constructor option for a 
default format type? Setting no default could fallback to one of the constants 
(which still doesn't resolve the non-consensus issue).


[2012-08-27 15:17:38] der...@php.net

We have had this a few times now, and we should not do this. The main reason is 
that we will never be able to come to a consensus on which format to show. It 
certainly shouldn't have anything that destroys the encoded timezone 
identifiers.

It's perfectly possible to subclass DateTime yourself and add a __toString() 
that returns the datetime in your preferred format though.


[2012-08-27 15:15:15] willfi...@php.net

This is a good idea.  I will add this, but will also add an RFC as I'd like the 
input of other internals on the output format.

------------
[2012-08-23 18:15:37] bdurand-php at ssji dot net

Description:

Hello,

I want to have a default behavior to convert an instance of the class DateTime 
into a string. I mean implement the method __toString() in the DateTime class.

The default format should be ISO8601 IMHO, but we can add an attribut to define 
the default format to use for __toString() and format() method.

Greetings.

Test script:
---
https://bugs.php.net/bug.php?id=62911&edit=1