Date Time Functions in Algolia - algolia

I have an object in Algolia like -
{
…
“startDate”: “2013-09-26T00:00:00.000+05:30”,
“endDate”: “2017-10-25T10:08:44.000+05:30”,
…
}
Now, while retrieving the object i want to add another field as -
“endingIn”: “Ending in 9 days”
“endingIn” is days remaining from todays date till endDate. Example:
val daysLeft = Days.daysBetween(DateTime.now,DateTime.parse(endDate)).getDays <br>
val endingIn = s"Ending In $daysLeft days"
Is it possible?
Thanks in advance.

you can use transformData.
from the doc :Method used to change the object passed to the item template

Related

Change input Date format? Vuejs + mongoose

Problem: Change the Date input field from "mm/dd/yyyy" to "dd/mm/yyyy".
I already know how to change after i receive the date, but the problem is that when the client is typing the input is still receiving "mm/dd/yyyy".
My mongoose schema:
const schemaRegister = new mongoose.Schema({
date: Date,
});
My input area:
<b-form-input v-mask="'##/##/####'" v-model="date"></b-form-input>
My date formating (using momentsjs):
changeDateFormat() {
let fixedDate = moment(this.registers[i].date).format("L");
this.registers[i].date = fixedDate;
}
I am displaying the 'fixedDate' on the table, but it doesn't help a lot because when the client is typing he thinks the first 2 slots are the days (dd), but in reality they are the month (mm). As a solution i thought of using the Date as a String but then it would make the verification very difficult.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
just pass the parameters in the correct order, like this:
new Date(day, monthIndex, year);
I wasn't using the 'momentsjs' correctly, first i needed to parse the input date by using
let formatedDate = moment(this.date,"DD-MM-YYYY");
and then for displaying the date i should have used
let fixedDate = moment(this.registers.date).format("DD/MM/YYYY");

How to assign current date to a date field in odoo 10

How to show current date before clicking the date field in odoo?
Odoo Date field class provides methods to get default values for like today.
For dates the method is called context_today() and for datetimes context_timestamp(). You are able to pass a timestamp to this methods to either get today/now (without timestamp) or a timestamp which will be formed by the logged in users timezone.
Code Example:
from odoo import fields, models
class MyModel(models.Model):
_name = 'my.model'
def _default_my_date(self):
return fields.Date.context_today(self)
my_date = fields.Date(string='My Date', default=_default_my_date)
Or the lambda version:
my_date = fields.Date(
string='My Date', default=lambda s: fields.Date.context_today(s))
I found it.It is Simple, just write this on your python code like:
date = fields.Datetime(string="Date", default=lambda *a: datetime.now(),required=True)
or
like this
date = fields.Datetime(string="Date current action", default=lambda *a: datetime.now())
or
like this
date = fields.Date(default=fields.Date.today)

Gravity Forms Date Push Reservations

I currently use GF for reservations 'Arrive' and 'Departure'. I would like the date displayed on the 'Departure' to always be one date ahead of the 'Arrival' date, regards of what date the guest picks. Then can pick a custom 'Departure' date, but as a default I'd like to show one date forward of the 'Arrival' date no matter what 'Arrival' date they choose.
This is possible with the gform_datepicker_options_pre_init JS filter. Example #3 is what you're after:
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 8 ) {
optionsObj.minDate = 0;
optionsObj.onClose = function (dateText, inst) {
jQuery('#input_12_9').datepicker('option', 'minDate', dateText).datepicker('setDate', dateText);
};
}
return optionsObj;
});
If you're looking for a code-less solution, I've written a plugin that let's you do this in just a few clicks called GP Limit Dates.
Also, here is an article that addresses your specific need: How to restrict dates in second date field based on date selected in first date field with Gravity Forms

In yii how to find date is greater than current date

I am working in Yii framework. I am having Poll table with fields as-
-pollId
-pollQuestion
-Isactive
-publishDate
-isPublish
when new poll is created,that date get inserted into publishDate field.
e.g.2012-04-04 02:23:45 In this format entry get inserted.
Now i want to check weather this publishDate is smaller than today's date or current date. i.e.publishDate should not be greater than current date.
So how to check this in yii? Please help me
As per normal PHP. Assuming $model is the submitted form and you have assigned (after the form has been submitted) $model->attributes = $_POST['MyModel']
You can then use:
if ($model->publishDate < date('Y-m-d H:i:s')){
// it is smaller
}
Another thing you could look at is using Yii's model validation. You could store the created date (which would be todays date) and then compare that to the publishDate in the form submit:
$model->created = date("Y-m-d H:i:s");
if ($model->validate){
...
}
And in your Poll model:
array('publishDate ','compare','created','operator'=>'<', 'message'=>'Publish Date must be smaller than the current date'),

Rally: how to pull latest testresult from a specific testset

I am trying to use the following code to get a pie chart for the latest testresult from a particular testset.
pieconfig = {
type: 'TestCaseResult',
attribute: 'Verdict',
query: rally.sdk.util.Query.and(['TestSet = "' + testsetDropdown.getValue() + '"','Date < "2012-11-01"'])
};
var pieChart = new rally.sdk.ui.PieChart(pieconfig,rallyDataSource);
pieChart.display("pieChartDiv");
In this code I've put today's date manually, but I want to make this query as of a generic type which should pull the latest testresult from a specific testset. Any hints...? Thank you.
Rally has a nice DateTime format that formats dates to whatever you want. Here's the reference you can use: http://developer.rallydev.com/help/datetime.
If you always want the current day in the year-month-day format, you can do this:
var dateQuery = 'Date < ' + rally.sdk.util.DateTime.format(new Date(), "yyyy-MM-dd");
Then your query will look something like this:
query: rally.sdk.util.Query.and(['TestSet = "' + testsetDropdown.getValue() + '"', dateQuery])
EDIT: Now I see what you mean by grabbing the latest TestCaseResult. You don't actually need the Date conditional in your query. What you need to add is a couple of options to your pie config.
var pieconfig = {
type: 'TestCaseResult',
attribute: 'Verdict',
query: '(Test Set = "' + testsetDropdown.getValue() + '")',
order: 'CreationDate desc',
pagesize: 1
};
This will sort by the Creation Date in descending order, which means the most recently made TestCaseResult will be on top. Setting a pagesize to 1 means you'll always get the most recent result.
This also solves the issue of not getting test case results of the current day. The previous query will get all TestCaseResults from today at 12:00AM backward. So any test case results made in the current day will not be included.
Let me know if that doesn't work out for you. I'm pretty new to the Rally SDK1 query system.