I use this code select object case MONTH
This my function in repository
public function findProductByCustomerIdGroupByCodeMc($id,$magasin,$periode)
{
$emConfig = $this->getEntityManager()->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
$qb = $this->createQueryBuilder('lead')
->select('lead')
->from('BOGeneralBundle:EtLeads', 'l')
if($periode != "0")
{
$qb->andWhere('MONTH(l.dataCreated) = :periode')
->setParameter('periode', $periode);
}
return$qb->getQuery()->getResult();
}
and put conduction because I have option for all Month and it value = 0
and the page display this message
Fatal error: Class 'DoctrineExtensions\Query\Mysql\Month' not found
For Doctrine2, you have to register your own function to recognize YEAR() MONTH() and DAY() in DQL
To do this you can install this bundle via composer. Just add it to your composer.json and then php composer.phar update beberlei/DoctrineExtensions
"beberlei/DoctrineExtensions": "*",
Then you can register functions to your ORM
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
dql:
datetime_functions:
DAY: DoctrineExtensions\Query\Mysql\Day
MONTH: DoctrineExtensions\Query\Mysql\Month
YEAR: DoctrineExtensions\Query\Mysql\Year
This article talks about this too.
Related
Could anyone explain code below for matching record in Aws glue
from manual https://aws.amazon.com/ru/blogs/big-data/work-with-partitioned-data-in-aws-glue/
I printed the full schema using githubEvents.printSchema():
id: string
type: string
actor: struct
repo: struct
payload: struct
public: boolean
created_at: string
year: string
month: string
day: string
org: struct
def filterWeekend(rec: DynamicRecord): Boolean = {
def getAsInt(field: String): Int = {
rec.**getField(field**) match {
case Some(strVal: String) => strVal.toInt
// The filter transformation will catch exceptions and mark the record as an error.
case _ => throw new IllegalArgumentException(s"Unable to extract field $field")
}
}
val (year, month, day) = (getAsInt("year"), getAsInt("month"), getAsInt("day"))
val cal = new GregorianCalendar(year, month - 1, day) // Calendar months start at 0.
val dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)
**dayOfWeek** == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY
}
val filteredEvents = githubEvents.filter(filterWeekend)
filteredEvents.count
I think that day should be ingested in getField(field) how glue knows that day should be compared but not other field so I mean we should compare day of the schema with dayofWeek?
I have the need to query all incomplete projects, wherein upon completion a project will be given a status change (Completed) plus a boolean isComplete==true.
I'm working through AWS Appsync to test the queries before I hard-code them into my app, but this one doesn't seem to be effective. I want all projects where isComplete==false or isComplete==null: boolean logic doesn't work with the input1 variable below (0 results).
{"__typename":{"S":"Project"},"addressLine1":{"S":"321 Faith Cir"},"city":{"S":"Perris"},"createdAt":{"S":"2019-03-05T01:01:39.513Z"},"currentOwner":{"S":"pgres52"},"dateRequired":{"S":"2019-03-13-07:00"},"id":{"S":"89a5-42ef7efef8fb"},"status":{"S":"Created"},"statusLastChangedAt":{"S":"2019-03-05T01:01:39.513Z"}}
{
"input1":{
"isComplete": {
"ne": true
}
}
}
query listNonCompleteProjects($input1: ModelProjectFilterInput) {
listProjects(filter: $input1, limit: 20) {
items {
id
currentOwner
addressLine1
city
dateRequired
isComplete
statusLastChangedAt
}
nextToken
}
}```
Solved! Partially helped with this post: Prisma.io: How do I filter items with certain fields being null?
I was able to get it to work with an additional parameter status (string):
query listNonCompleteProjects($input1: ModelProjectFilterInput) {
listProjects(filter: $input1, limit: 20) {
items {
...
}
}
}
"input1":{
"and": [
{"status": {"notContains": "Complete"}},
{"isComplete": {
"ne": true
}}
]
},
I am trying to pass a replacement datepicker on the site with the geb tests we are running.
it is failing on handling an American mock test
{{pikaday-input
value=localisedValue
format=(if format format "DD/MM/YYYY")
name=name
placeholder=localisedPlaceholder
onSelection=(action setValue)
id=inputId
classNames="date-placeholder"
tabindex=tabIndex
}}
date.js
import LocalisedTextInput from './localised-text-input';
export default LocalisedTextInput.extend({
setValue(dateValue) {
if(dateValue) {
let valueFormat = this.get('valueFormat') ? this.get('valueFormat') : 'YYYY-MM-DD';
if(valueFormat !== 'date') {
dateValue = window.moment(dateValue).format(valueFormat);
}
else {
dateValue = window.moment(dateValue);
}
}
this.set('localisedValue', dateValue);
}
});
and the test
def "Agenda Day renders correctly in the US"() {
given:
bootstrapPublishedTestEvent()
and:
def page = asyncTo EditAgendaPage, siteUnderTest
when:
page.mockTimeZone(420)
page.addDay('20/02/2016', 'Day 1')
then:
page.days*.date == ["20/02/2016"]
}
when I comment out page.mockTimeZone(420) -- the test passes.
mockTimeZone is using the TimeShift.js lib
Date = TimeShift.Date;
TimeShift.setTimezoneOffset(420);
there is a bug that if the date from the server is 31/12/2019 - in UK timezone it is correct -- but in the US timezone it shows as 30/12/2019
How to add expiry date to Angular 2 cookie. I am trying with Angular 2.0.0-beta.15. When i try to add options like below:
var expireDate = new Date (new Date().getTime() + (1000 * data.expires_in));
this._cookieService.put('token', this.token, {expires: expireDate});
above code throwing error like "[ts] Argument of type '{ expires: Date; }' is not assignable to parameter of type 'CookieOptionsArgs'.
Property 'path' is missing in type '{ expires: Date; }'. (local var)
expireDate: Date"
I can see on https://www.npmjs.com/package/angular2-cookie to override default options globally. I doubt if this is the method to add expiry date to cookie? Can somebody help me to understand more on this?
I have used this library with success: https://github.com/BCJTI/ng2-cookies. Use it like below with setting expiry date:
Include the lib:
import {Cookie} from 'ng2-cookies/ng2-cookies';
Set a cookie with expiry date of 365 days:
Cookie.setCookie("cookie-key", "cookie-value", 365);
A little bit late but Should be something like this
let key = 'testCookieKey';
let value = 'testCookieValue';
let opts: CookieOptionsArgs = {
expires: new Date('2030-07-19')
};
cookieService.put(key, value, opts);
Hope that
For Expiry date parameter in set cookies the value should be seconds to days calculation.
i.e. 2 min = (2/1440)
//use for 2 minutes....
auth-cookies.ts
import { Injectable } from '#angular/core';
import { Cookie } from 'ng2-cookies/ng2-cookies';
#Injectable()
export class AuthCookie {
constructor() { }
getAuth(): string {
return Cookie.get('id_token');
}
setAuth(value: string): void {
//0.0138889=20 minuts
//this accept day not minuts
//use for 20 minuts
Cookie.set('cookie_token', value, 0.0138889);
//use for 2 minuts
// Cookie.set('cookie_token', value,0.00138889)
}
deleteAuth(): void {
Cookie.delete('id_token');
}
}
i post it too late but hope this will be useful.
How can I simulate the behavior of grails.databinding.dateFormats in a controller spock test?
In my Config.groovy, I added these settings:
grails.databinding.dateFormats = [
'yyyy-MM-dd\'T\'HH:mm:ss.SSSX',
'yyyy-MM-dd\'T\'HH:mm:ssX',
]
What do I have to do to get the unit test framework to bind date properties using one of the specified formats?
My controller looks like:
class MyController {
static responseFormats = ['json']
def get() {
MyCommand command = bindData(new MyCommand(), params)
command.validate()
if (command.hasErrors()) {
...
}
else {
//...do stuff with command object
}
}
#Validateable
class MyCommand {
Long resourceId
Date startDate
Date endDate
static constraints = {
resourceId nullable: false
startDate nullable: false
endDate nullable: false
}
}
}
When I run the application, this code works normally; however, when bindData() is called in the unit test, the 'resourceId' property on the command object is populated, while the date properties are not.