Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SnakTime.php #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucamauri
Copy link
Contributor

Insure the instant is always set to 00:00:00 otherwise the API call will fail

Insure the instant is always set to 00:00:00 otherwise the API call will fail
@valerio-bozzolan
Copy link
Owner

Thank you!

Can you also share a small API request to Wikidata, as a way to test this?

Just a copy-paste in a comment would be OK

@lucamauri
Copy link
Contributor Author

Can you also share a small API request to Wikidata, as a way to test this?

Following please find details of the tests I performed on Wikidata.

Preamble

Consider the following code fragment as base code used:

$timeObject = new \DateTime();
$timeObject->setTimezone(new \DateTimeZone('UTC'));
$timeObject->setDate(2016, 6, 19);
$timeObject->setTime(9, 3, 36);

$timeString = "+2016-06-19T09:03:36Z";

// Set P571 (inception date)
$statement = new \wb\StatementTime("P571", **VariableAsAbove**, 11);
$newdata->addClaim($statement);

$wikidata->login();

// this tries to save all your proposed changes in the Wikidata Sandbox
$newdata->editEntity([
    'id' => 'Q4115189',
    'summary' => "Test time precision with boz-mw",
]);

Original

Launching this code with the original version of the bot results in the exception:

PHP Fatal error:  Uncaught mw\API\ModificationFailedException: API error code: 'modification-failed' info: 'Malformed input: +2016-06-19T09:03:36Z' in […]/boz-mw/include/mw/API/Exception.php:81

both using $timeObject and $timeString as input variable.

Modification

On the contrary, modifying the code as suggested in this pull request results in a succesful execution
image
again, both using $timeObject and $timeString as input variable.

Note on precision

Note that using a precision of 14 (meaning "seconds" as explained here https://phabricator.wikimedia.org/T57755) results in an exception from the API in all cases:

PHP Fatal error:  Uncaught mw\API\ModificationFailedException: API error code: 'modification-failed' info: 'Out of range, must be no higher than 11' in […]/boz-mw/include/mw/API/Exception.php:81

Conclusion

I hope to have covered all the cases with these tests. If you deem necessary further investigation, just let me know.

@valerio-bozzolan
Copy link
Owner

Thanks again for this very professional patch

Also looking at

https://www.wikidata.org/wiki/Help:Dates#Hours,_minutes_and_seconds

Probably, to add future-compatibility, we could wrap everything inside a:

// below this precision, setting time will very probably cause a server validation error
if( $precision <= 11 ) {
    ....
}

@lucamauri
Copy link
Contributor Author

Probably, to add future-compatibility, we could wrap everything inside a:

// below this precision, setting time will very probably cause a server validation error
if( $precision <= 11 ) {
    ....
}

I see your point, but at first sight this might be misleading to the user.
A user might be tempted to use precision value above 11 without realising that this would generate an exception anyway.
What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants