Example usage for org.apache.solr.request SolrRequestInfo getNOW

List of usage examples for org.apache.solr.request SolrRequestInfo getNOW

Introduction

In this page you can find the example usage for org.apache.solr.request SolrRequestInfo getNOW.

Prototype

public Date getNOW() 

Source Link

Usage

From source file:test.DateMathParser.java

License:Apache License

/**
 * Returns a clone of this instance's concept of "now" (never null).
 * <p>//from  www.ja  v a2 s .  c  o  m
 * If setNow was never called (or if null was specified) then this method
 * first defines 'now' as the value dictated by the SolrRequestInfo if it
 * exists -- otherwise it uses a new Date instance at the moment getNow()
 * is first called.
 *
 * @see #setNow
 * @see SolrRequestInfo#getNOW
 */
public Date getNow() {
    if (now == null) {
        SolrRequestInfo reqInfo = SolrRequestInfo.getRequestInfo();
        if (reqInfo == null) {
            // fall back to current time if no request info set
            now = new Date();
        } else {
            now = reqInfo.getNOW(); // never null
        }
    }
    return (Date) now.clone();
}