Closing parenthesis of a multi-line function call must be on a line by itself - phpcs

I am getting this message from phpcs. my code is:
$userdata["expirydate"] = date("Y-m-d H:i:s", mktime(date("H"), date(
"i"), date("s"), date("m"), date("d") - 1, date("y")));

Your date("i") function call spans multiple lines. When this happens, that rule is enforcing that the closing parenthesis be on a line by itself.
If you want to adhere to that rule, you've got a a few options for reformatting your code.
You could use the PHPCS diff report to see how PHPCS wants you to format it. In this case, using --report=diff shows:
--- temp.php
+++ PHP_CodeSniffer
## -1,3 +1,4 ##
<?php
$userdata["expirydate"] = date("Y-m-d H:i:s", mktime(date("H"), date(
- "i"), date("s"), date("m"), date("d") - 1, date("y")));
+ "i"
+), date("s"), date("m"), date("d") - 1, date("y")));
Which means PHPCS thinks the smallest change you could make would be to write your code like this:
$userdata["expirydate"] = date("Y-m-d H:i:s", mktime(date("H"), date(
"i"
), date("s"), date("m"), date("d") - 1, date("y")));
Which is valid, but not great.
You could put it all on one long line, which is still valid:
$userdata["expirydate"] = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - 1, date("y")));
You could split up the main date() call to make it valid and keep the line lengths shorter:
$userdata["expirydate"] = date(
"Y-m-d H:i:s",
mktime(date("H"), date("i"), date("s"), date("m"), date("d") - 1, date("y"))
);
Or you could even put every argument on a new line:
$userdata["expirydate"] = date(
"Y-m-d H:i:s",
mktime(
date("H"),
date("i"),
date("s"),
date("m"),
date("d") - 1,
date("y")
)
);
It really depends on which code block you find more readable, and which code block fits best with your existing coding standard.

Related

whereBetween doesn't work in laravel mongodb

Hello I'm new in MongoDB laravel and I have the following error:
This is the object I want to query in Mongo.
MongoDB Compass
I want to fetch timestamps that are greater than or equal to 2022/7/5 and less than or equal to 2022/7/6, according to my logic in Laravel with the Jenssegers/laravel-mongodb, would have this:
$tracks = TrackFishing::where('boat_id', '3')
->whereBetween(
'tracking.timestamp', array(
Carbon::createFromDate(2022, 7, 5),
Carbon::createFromDate(2022, 7, 6)
))
->first();
I want to get position 0 of the timestamp but this throws me empty, I'd appreciate your help
You need to specify the hour, minute and second
$tracks = TrackFishing::where('boat_id', '3')
->whereBetween(
'tracking.timestamp', array(
Carbon::createFromDate(2022, 7, 5)->startOfDay(),
Carbon::createFromDate(2022, 7, 6)->endOfDay()
))
->first();
I solved with a aggregate:
$cursor = Model::raw()->aggregate([
['$match' => [
'tracking.timestamp' => [
'$gte' => new \MongoDB\BSON\UTCDateTime(Carbon::createFromFormat("Y-m-d", $request->fecha_inicio)->startOfDay()),
'$lte' => new \MongoDB\BSON\UTCDateTime(Carbon::createFromFormat("Y-m-d", $request->fecha_fin)->endOfDay())
],
]
],
]);
this question helped me
thank you all for replying
try with this one;
'tracking.timestamp', [
Carbon::createFromDate(2022, 7, 5),
Carbon::createFromDate(2022, 7, 6)
]

Difference between two dates in Laravel

I have a problem with difference between two days.
How is it possible to get number of days?
Here is my code,
$start = date('Y-m-d', strtotime("+1 day"));
$end = date('Y-m-d', strtotime("+7 day"));
I use Pure PHP :
$start = date('Y-m-d', strtotime("+1 day"));
$end = date('Y-m-d', strtotime("+7 day"));
$diff = abs(strtotime($start) - strtotime($end));
$days = floor($diff/60/60/24);
$total = sprintf("%d days\n", $days);
return $total; // 6 days

Carbon - "The date does not match the format d/m/Y H:i:s."

'm trying to store a date value but is always appearing the validation error:
"The date does not match the format d/m/Y H:i:s."
Do you know where can be the issue? Validate method:
$this->validate($request, [
'date1' => 'required|date_format:d/m/Y H:i:s',
'date2' => 'required|date_format:d/m/Y H:i:s|after_or_equal:date1',
]);
To create Im using carbon to format the dates:
Carbon::createFromFormat('d/m/Y H:i:s', $request->date1)
Carbon::createFromFormat('d/m/Y H:i:s', $request->date2)
The Js code is:
$( ".input-group.date").datetimepicker({
format: "dd MM yyyy - hh:ii",
autoclose: true,
todayBtn: true,
minuteStep: 5
});
Since you're passing the date string in dd MM yyyy - hh:ii format, change validation rules date format too:
'date1' => 'required|date_format:d F Y - H:i',
'date2' => 'required|date_format:d F Y - H:i|after_or_equal:date1',
And then use the same format to create Carbon instance:
Carbon::createFromFormat('d F Y - H:i', $request->date1)
Carbon::createFromFormat('d F Y - H:i', $request->date2)

Why does the Stanford NER demo convert 'this year' to 2017, whereas my CoreNLP server does not?

I have set up a CoreNLP server and am using Stanford NER to extract time periods from sentences.
If I use the online interactive demo at corenlp.run to parse the sentence
'Last year something happened.'
it shows 'DATE' and '2016'.
However, my own server, set up with the latest release of CoreNLP, only shows 'DATE'. What's more, when I use Python Requests to query my server's API with the same sentence, the first two tokens in the response contain the fields 'timex': {'type': 'DATE','tid': 't1', 'altValue': 'THIS P1Y OFFSET P-1Y'} and 'normalizedNER': 'THIS P1Y OFFSET P-1Y'.
If I just have to deal with the fact that my output is not as good as the demo's, then where is the Stanford NER or timex3 documentation explaining what THIS P1Y OFFSET P-1Y means or describing what other possible responses I might get in the normalizedNER field?
Here is the entire API response
[
{'word': 'Last', 'after': ' ', 'originalText': 'Last', 'timex': {'type': 'DATE', 'tid': 't1', 'altValue': 'THIS P1Y OFFSET P-1Y'}, 'pos': 'JJ', 'ner': 'DATE', 'lemma': 'last', 'normalizedNER': 'THIS P1Y OFFSET P-1Y', 'before': '', 'index': 1, 'characterOffsetBegin': 0, 'characterOffsetEnd': 4},
{'word': 'year', 'after': ' ', 'originalText': 'year', 'timex': {'type': 'DATE', 'tid': 't1', 'altValue': 'THIS P1Y OFFSET P-1Y'}, 'pos': 'NN', 'ner': 'DATE', 'lemma': 'year', 'normalizedNER': 'THIS P1Y OFFSET P-1Y', 'before': ' ', 'index': 2, 'characterOffsetBegin': 5, 'characterOffsetEnd': 9},
{'word': 'something', 'before': ' ', 'originalText': 'something', 'ner': 'O', 'lemma': 'something', 'after': ' ', 'characterOffsetEnd': 19, 'index': 3, 'characterOffsetBegin': 10, 'pos': 'NN'},
{'word': 'happened', 'before': ' ', 'originalText': 'happened', 'ner': 'O', 'lemma': 'happen', 'after': '', 'characterOffsetEnd': 28, 'index': 4, 'characterOffsetBegin': 20, 'pos': 'VBD'},
{'word': '.', 'before': '', 'originalText': '.', 'ner': 'O', 'lemma': '.', 'after': '', 'characterOffsetEnd': 29, 'index': 5, 'characterOffsetBegin': 28, 'pos': '.'}
]
If you closely look at the request made to corenlp server in the interactive demo, then you will see that current date is also sent as "date" parameter with the request.
For eg. If your sentence is "I went to school today.", then "today" has normalized ner is "2017-19-09" (current date).
If you dont pass the "date" parameter, "today" won't have the exact date as normalized ner.
Hope it makes sense.
Hi I have added a new feature to allow you to tell the pipeline to use the present date as the docDate when running, this is the main source of your issue. To get this feature you will have to use the latest version of Stanford CoreNLP available on GitHub.
Also, when you start the server you will have to use the -serverProperties option and supply a .properties file with these properties:
annotators = tokenize,ssplit,pos,lemma,ner,entitymentions
ner.usePresentDateForDocDate = true
If you do this it should work now and properly list 2016

Joomla - get one year and one month time()

I can get the current date&time by using
$today = JHTML::_('date', time(), '%Y-%m-%d %H:%M:%S');
echo $today;
How to I get 1year later and 1month later base on $today??
eg.now:2011-12-10 13:00:01
How to get 2012-12-10 13:00:01 AND 2012-01-10 13:00:01
It might not be the best way to do it, but this should work:
$time = mktime( date("H"), date("i"), date("s"), date("m")+1, date("d"), date("Y") + 1);
JHTML::_( 'date', $time, '%Y-%m-%d %H:%i:%s');
Alternatively, if you are using PHP 5.3, you can use the DateTime object.
I hope it helped!

Resources