Problem/Motivation

The documentation for DateTimePlus is incomplete. And needs to be improved.

API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Date...

See for instance https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Date.... The '@see __construct()' is not forming a link.

Proposed resolution

Change the documentation according to https://www.drupal.org/docs/develop/standards/api-documentation-and-comm....

Remaining tasks

Documentation to be written and updated.

Issue fork drupal-3077520

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joachim created an issue. See original summary.

gueguerreiro’s picture

Title: DateTimePlus has badly-formed @see links in numerous parameters » Fix and improve DateTimePlus documentation
Related issues: +#2940420: @see should not be used inside a @param description

This would be a duplicate of https://www.drupal.org/project/drupal/issues/2940420, but I was looking through the documentation for that class in more detail and there are a couple more documentation errors there. I think we can turn this one into a general fix for documentation errors/improvements for DateTimePlus?

Most of my assumptions are according to what's currently in https://www.drupal.org/node/1354, but I assume all of what's in there to be correct.

The class docblock

 * @method $this add(\DateInterval $interval)
 * @method static array getLastErrors()
 * @method $this modify(string $modify)
 * @method $this setDate(int $year, int $month, int $day)
 * @method $this setISODate(int $year, int $week, int $day = 1)
 * @method $this setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0)
 * @method $this setTimestamp(int $unixtimestamp)
 * @method $this setTimezone(\DateTimeZone $timezone)
 * @method $this sub(\DateInterval $interval)
 * @method int getOffset()
 * @method int getTimestamp()
 * @method \DateTimeZone getTimezone()

Uses @method tags. While these are correct according to phpdoc, the Drupal API doesn't support them. The page displays these as a huge paragraph:

@method $this add(\DateInterval $interval) @method static array getLastErrors() @method $this modify(string $modify) @method $this setDate(int $year, int $month, int $day) @method $this setISODate(int $year, int $week, int $day = 1) @method $this setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0) @method $this setTimestamp(int $unixtimestamp) @method $this setTimezone(\DateTimeZone $timezone) @method $this sub(\DateInterval $interval) @method int getOffset() @method int getTimestamp() @method \DateTimeZone getTimezone()

The @param $timezone docblocks:

   * @param mixed $timezone
   *   (optional) \DateTimeZone object, time zone string or NULL. NULL uses the
   *   default system time zone. Defaults to NULL.

Have a type of mixed. A more correct value would be, as the description states, \DateTimeZone|string|null

The @param $settings docblock on __construct():

   * @param array $settings
   *   (optional) Keyed array of settings. Defaults to empty array.
   *   - langcode: (optional) String two letter language code used to control
   *     the result of the format(). Defaults to NULL.
   *   - debug: (optional) Boolean choice to leave debug values in the
   *     date object for debugging purposes. Defaults to FALSE.

The only operation with the $settings parameter is the following:

    // Unpack settings.
    $this->langcode = !empty($settings['langcode']) ? $settings['langcode'] : NULL;

The 'debug' key is never used. It should be removed.
Also, according to the API documentation and comments standards:

The line before a list or before a new level of nesting must end with a colon (:).

The @param time docblock on createFromFormat():

   * @param mixed $time

The type is documented as mixed. It is actually a string, the same one accepted at https://www.php.net/manual/en/datetime.construct.php and the same type as most of the other $type parameters on that class.

Of course, multiple instances of @see tags as a child of the @param tag:

   * @param mixed $time
   *   @see __construct()
   * @param mixed $timezone
   *   @see __construct()

I don't think a @see __construct() is even needed in the first place. We can just copy the description of these parameters from the __construct() and paste it there. If we do need it we should link it at the very bottom of the docblock, as @see self::__construct() instead.
Note that the $settings param from createFromFormat() is the same as __construct(), with the exception that it can also contain a "validate_format" key. It seems to be the only one that is any different from the other ones.

Also some nitpicks:

  /**
   * A RFC7231 Compliant date.
   *
   * @see http://tools.ietf.org/html/rfc7231#section-7.1.1.1
   *
   * Example: Sun, 06 Nov 1994 08:49:37 GMT
   */
  const RFC7231 = 'D, d M Y H:i:s \G\M\T';

The description text should be after the short description text, and the @see tag should be at the bottom.

gueguerreiro’s picture

Status: Active » Needs review
StatusFileSize
new9.89 KB

This patch should address the issues raised on #3. In addition to those, I added some @see tags (And regular See links, when using them inside @params) where I thought appropriate.

gueguerreiro’s picture

I had some trailing whitespaces. This one fixes those.

volkswagenchick’s picture

Issue tags: +badcamp2019

Tagging this for badcamp2019. (October 2-5)

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

capysara’s picture

Patch in #4 applies cleanly to 8.9.

joachim’s picture

Status: Needs review » Needs work

Thanks everyone for working on this!

  1. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -129,7 +118,9 @@ class DateTimePlus {
    +   *   (optional) Keyed array of settings. Defaults to empty array. Possible values include:
    

    This line needs wrapping.

  2. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -129,7 +118,9 @@ class DateTimePlus {
    +   *   - langcode: (optional) String two letter language code used to control
    

    A two-letter language code is an ISOwhatsit, right? We should say that.

  3. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -146,12 +137,18 @@ public static function createFromDateTime(\DateTime $datetime, $settings = []) {
    +   *   (optional) Keyed array of settings. Defaults to empty array. Possible values include:
    

    Wrapping.

  4. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -182,16 +179,26 @@ public static function createFromArray(array $date_parts, $timezone = NULL, $set
    -   *   @see __construct()
    

    It might be better to keep a reference to __construct() rather than repeating the same docs.

    The question in my original report was really -- how should this be made correctly?

joachim’s picture

According to #2989497: Link to 'self::method()' doesn't work in documentation blocks, '@see self::__construct()' should work.

mradcliffe’s picture

I added the needs issue summary update tag because I think that it is a bit unclear what is left to be done on the issue. We should apply the standard issue summary template. THe issue summary should include the current state of the issue with respect to @joachim's comments and the latest patch.

mradcliffe’s picture

Issue tags: +Novice

Adding novice tag.

Hmengland’s picture

I'm working on this ticket at DrupalCon Amsterdam

Hmengland’s picture

Issue summary: View changes

updated issue summary to follow the standard issue summary template.

shubham.prakash’s picture

Status: Needs work » Needs review
StatusFileSize
new9.97 KB

Changes have been made as per #8 and #9

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

neclimdul’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
@@ -24,18 +24,7 @@
  *
- * @method $this add(\DateInterval $interval)
- * @method static array getLastErrors()
- * @method $this modify(string $modify)
- * @method $this setDate(int $year, int $month, int $day)
- * @method $this setISODate(int $year, int $week, int $day = 1)
- * @method $this setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0)
- * @method $this setTimestamp(int $unixtimestamp)
- * @method $this setTimezone(\DateTimeZone $timezone)
- * @method $this sub(\DateInterval $interval)
- * @method int getOffset()
- * @method int getTimestamp()
- * @method \DateTimeZone getTimezone()

These are all IDE hints. Unfortunate that Drupal API doesn't support them but removing them is a big DX hit so seems a no go.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

ayushmishra206’s picture

StatusFileSize
new47.18 KB

Patch #14 Fails to Apply. Needs Reroll.

kishor_kolekar’s picture

Status: Needs work » Needs review
StatusFileSize
new6.48 KB

here the re-roll patch

alvar0hurtad0’s picture

Status: Needs review » Needs work

This still needs to address the comment #16

alvar0hurtad0’s picture

Status: Needs work » Needs review
StatusFileSize
new1.12 KB
new6.46 KB

This patch fixes #16

gueguerreiro’s picture

Addressing #16, I looked into it a bit more, and there is an issue to add the @method tags for the magic methods to the DateTimePlus docblock on #2902707: Document magic methods in DateTimePlus and DrupalDateTime using phpDoc @method. There's also an issue opened to support these on the Drupal Coding Standards API here #2920333: Allow PHPDoc @method annotations in class headers., which I agree with.

We should keep them and focus the attention on changing the Drupal Coding Standards API instead.

neclimdul’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -25,17 +25,30 @@
      * @method $this add(\DateInterval $interval)
    + * ¶
      * @method static array getLastErrors()
    + * ¶
      * @method $this modify(string $modify)
    + * ¶
      * @method $this setDate(int $year, int $month, int $day)
    + * ¶
      * @method $this setISODate(int $year, int $week, int $day = 1)
    + * ¶
      * @method $this setTime(int $hour, int $minute, int $second = 0, int $microseconds = 0)
    + * ¶
      * @method $this setTimestamp(int $unixtimestamp)
    + * ¶
      * @method $this setTimezone(\DateTimeZone $timezone)
    + * ¶
      * @method $this sub(\DateInterval $interval)
    + * ¶
      * @method int getOffset()
    + * ¶
      * @method int getTimestamp()
    + * ¶
    

    Don't understand why these need space. also, trailing spaces.

  2. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -46,9 +59,9 @@ class DateTimePlus {
    -   * @see http://tools.ietf.org/html/rfc7231#section-7.1.1.1
    -   *
        * Example: Sun, 06 Nov 1994 08:49:37 GMT
    +   *
    +   * @see http://tools.ietf.org/html/rfc7231#section-7.1.1.1
    

    not sure why we're moving this. Also maybe relevant to documenting this. #3177385: Deprecate DateTimePlugs::DATE_RFC7231 constant

  3. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -195,6 +215,8 @@ public static function createFromArray(array $date_parts, $timezone = NULL, $set
    +   *
    +   * @see self::format()
        */
    

    What does format have to do with createFromTimestamp? Side note, I still don't understand why we can't use see comments per the phpdoc standard.

  4. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -237,6 +259,9 @@ public static function createFromTimestamp($timestamp, $timezone = NULL, $settin
    +   * @see self::format()
    

    again, why format?

  5. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -279,19 +304,20 @@ public static function createFromFormat($format, $time, $timezone = NULL, $setti
    +   *   (optional) Keyed array of settings. Defaults to empty array. Possible values include:
    
    @@ -677,12 +705,15 @@ public static function datePad($value, $size = 2) {
    +   *   (optional) Keyed array of settings. Defaults to empty array. Possible values include:
    

    >80 character comments.

  6. +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    @@ -724,6 +755,8 @@ public function setDefaultDateTime() {
    +   *
    +   * @see https://www.php.net/manual/en/class.datetime.php
    

    Does this provide extra context? Isn't the return time clear?

Additional note, I think links to php.net documentation are suppose to remove the language from the path so it redirects for non-english speakers.

sarvjeetsingh’s picture

StatusFileSize
new5.87 KB
new3.76 KB

Updated the patch as suggested in #23.
- For point 3&4, the use of format() method is mentioned in the comment and I think that's why it is referenced.

/**
   * Creates a date object from timestamp input.
   *
   * The timezone of a timestamp is always UTC. The timezone for a
   * timestamp indicates the timezone used by the format() method.

- Not sure about point 2. still needs to be addressed.

sarvjeetsingh’s picture

Status: Needs work » Needs review
abhijith s’s picture

StatusFileSize
new11.31 KB

Applied patch #24 and it is working fine.The problems addressed in #23 is fixed accordingly.

applied

abhijith s’s picture

Status: Needs review » Reviewed & tested by the community
quietone’s picture

Status: Reviewed & tested by the community » Needs work

In #24 there is a comment that #23.2 needs to be addressed.

Also #23.6 needs to be answered.

I think this still needs and Issue Summary Update. The proposed resolution is simply a link to the API documentation standards which is a useful link but there is nothing to state what is exactly to be improved here. As a reviewer, it is impossible to know if the patch fixes the issue.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kunalgautam’s picture

Status: Needs work » Needs review
StatusFileSize
new6.04 KB

Updated patch for Drupal version 10.1.x

smustgrave’s picture

Status: Needs review » Needs work

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

FYI #24 still cleanly applies to 10.1 so removing credit for #33

@kkalashnikov you can test by clicking retest.

Points in #28 still need to happen.

nitin_lama’s picture

Assigned: Unassigned » nitin_lama
nitin_lama’s picture

Status: Needs work » Needs review
StatusFileSize
new5.97 KB
new747 bytes

Addressed #23.2
Here's the updated patch. Please review.

nitin_lama’s picture

Assigned: nitin_lama » Unassigned
smustgrave’s picture

Status: Needs review » Needs work

FYI if you’re only going to address 1 point and not attempt the others the ticket is not ready for review

bharath-kondeti made their first commit to this issue’s fork.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Issue tags: -Novice

I think that in the state this issue is in it is no longer suitable for as a Novice issue. I am removing the 'Novice' tag because there isn't sufficient detail for someone new to Drupal contribution. Issues tagged Novice should met the criteria list in What makes a good novice task.