4an70m / apex-query-builder

Convenient query builder for dynamic SOQL queries
MIT License
53 stars 25 forks source link

Datetime support #12

Open kratoon opened 3 years ago

kratoon commented 3 years ago

Currently no datetime is supported.

Something like this would be appreciated. Also date literals would be great.

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

private static final String GMT_DATE_FORMAT = 'yyyy-MM-dd\'T\'HH:mm:ss\'Z\'';

public class CompareCondition extends FieldCondition {
        ....
        public Condition lt(Datetime fieldValue) {
            this.formedCondition = this.fieldName + ' < ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
            return this;
        }

        public Condition gt(Datetime fieldValue) {
            this.formedCondition = this.fieldName + ' > ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
            return this;
        }

        public Condition lte(Datetime fieldValue) {
            this.formedCondition = this.fieldName + ' <= ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
            return this;
        }

        public Condition gte(Datetime fieldValue) {
            this.formedCondition = this.fieldName + ' >= ' + fieldValue.formatGmt(GMT_DATE_FORMAT);
            return this;
        }
}