Beispiel #1
0
int64_t
kutil_date2epoch(int64_t day, int64_t mon, int64_t year)
{

	if (year < 1970 || mon < 0 || year < 0)
		return(0);
	return(mkdate(day, mon, year) -
	       mkdate(1, 1, 1970));
}
Beispiel #2
0
static unsigned char ps2_rtc_read_data(unsigned long addr)
{
	struct timeval tv;
	unsigned char res;

	if (13 < addr) {
		DPRINT("RTC: read rtc[%11s(%ld)]=0(ignored)\n", "???", addr);
		return (0);
	}

	do_gettimeofday(&tv);
	mkdate(tv.tv_sec,
	       &regs[RTC_YEAR], &regs[RTC_MONTH], &regs[RTC_DAY_OF_MONTH],
	       &regs[RTC_HOURS], &regs[RTC_MINUTES], &regs[RTC_SECONDS],
	       &regs[RTC_DAY_OF_WEEK]);

	regs[RTC_YEAR] -= 1952; /* Digital UNIX epoch */
	regs[RTC_YEAR] %= 100;
	res = (regs[addr] & 0xff);

	if (regs[RTC_CONTROL] & RTC_DM_BINARY) {
		DPRINT(" read rtc[%11s(%2ld)]=%d\n",
		       reg_names[addr], addr, res);
	} else {
		BIN_TO_BCD(res);
		DPRINT(" read rtc[%11s(%2ld)]=0x%02x\n",
		       reg_names[addr], addr, res);
	}

	return (res);
}
Beispiel #3
0
    /**
     *  @brief  Checks product end date attribute.
     *  @param  isIncluded true if included; false otherwise.
     *  @param  valueToCheck attribute value to check against.
     *  @param  value resulted attribute value from query.
     */
static
void
checkProductIncludedEndDate( bool &isIncluded, U32_t valueToCheck, std::string &value )
{
    if ( value == "ALL" )
    {
        isIncluded  = true;
    }
    else
    if ( value == "NONE" )
    {
        isIncluded  = false;
    }
    else
    {
        struct tm       ctm     = { 0 };
        DateC19_t       date    = 0;

        sscanf( value.c_str(), "%d-%d-%d", &ctm.tm_year, &ctm.tm_mon, &ctm.tm_mday );
        ctm.tm_year    -= 1900;
        ctm.tm_mon     -= 1;
        date            = mkdate( &ctm );

        if ( date >= valueToCheck )
        {
            isIncluded  = isIncluded == false ? true : false;
        }
    }
}
Beispiel #4
0
bool
draw_date(struct view *view, struct time *time)
{
	const char *date = mkdate(time, opt_show_date);
	int cols = opt_show_date == DATE_SHORT ? DATE_SHORT_WIDTH : DATE_WIDTH;

	if (opt_show_date == DATE_NO)
		return FALSE;

	return draw_field(view, LINE_DATE, date, cols, ALIGN_LEFT, FALSE);
}
Beispiel #5
0
Datei: draw.c Projekt: bbolli/tig
bool
draw_date(struct view *view, struct view_column *column, const struct time *time)
{
	enum date date = column->opt.date.show;
	const char *text = mkdate(time, date);

	if (date == DATE_NO)
		return FALSE;

	return draw_field(view, LINE_DATE, text, column->width, ALIGN_LEFT, FALSE);
}
Beispiel #6
0
static bool
draw_date(struct view *view, struct view_column *column, const struct time *time)
{
	enum date date = column->opt.date.display;
	const char *text = mkdate(time, date);
	enum align align = date == DATE_RELATIVE ? ALIGN_RIGHT : ALIGN_LEFT;

	if (date == DATE_NO)
		return false;

	return draw_field(view, LINE_DATE, text, column->width, align, false);
}
Beispiel #7
0
Datei: blame.c Projekt: peff/tig
static bool
blame_grep(struct view *view, struct line *line)
{
	struct blame *blame = line->data;
	struct blame_commit *commit = blame->commit;
	const char *text[] = {
		blame->text,
		commit ? commit->title : "",
		commit ? commit->id : "",
		commit ? mkauthor(commit->author, opt_author_width, opt_show_author) : "",
		commit ? mkdate(&commit->time, opt_show_date) : "",
		NULL
	};

	return grep_text(view, text);
}
Beispiel #8
0
    /**
     *  @brief  Retrieves saleable product details given search
     *          criteria.
     *  This (C++) function returns saleable product details that
     *  satisfy the specified search criteria.
     *  @note   Products with product price of zero are excluded
     *          from the saleable product list.
     *  @param  products returned Json:Value object containing
     *          saleable product details. The returned JSON object
     *          has the following format,
     *  @code
     *  {
     *    "products":
     *    [
     *      {
     *        "GSTApplicable":false,
     *        "PLU":"4. myki Child",
     *        "Price":50,
     *        "id":46,
     *        "issuer_id":1,
     *        "long_desc":"GTS Timetable",
     *        "short_desc":"GTS Timetable",
     *        "subtype":"None",
     *        "type":"ThirdParty"
     *      },
     *      { ... },
     *      null
     *    ]
     *  }
     *  @endcode
     *  where,
     *  @li     @c id is the product id (1-255).
     *  @li     @c issuer_id is the product issuer/owner id.
     *  @li     @c type is the product type, eg. "ThirdParty", "PremiumSurcharge".
     *  @li     @c subtype is the product sub-type, eg. "None".
     *  @li     @c long_desc is the product long description.
     *  @li     @c short_desc is the product short description.
     *  @li     @c Price is the product price in lowest denomination (cents).
     *  @li     @c GSTApplicable is true if GTS is applicable, false otherwise.
     *  @li     @c PLU is (optional) 'Price Lookup Unit' uniquely identifies product.
     *  @param  zone zone to validate against sales zones.
     *  @param  productType product type to search for (eg. "ThirdParty").
     *  @param  time time to validate against.
     *  @param  serviceProviderId service provider id.
     *  @param  deviceType device type (eg. "BDC").
     *  @return true if successful; false otherwise.
     */
int
getProducts(
    Json::Value    &products,
    int             zone,
    const char     *productType,
    Time_t          time,
    int             serviceProviderId,
    const char     *deviceType )
{
    #define MYKI_CD_DOW_SUNDAY      7

    int             returnValue     = false;
    DateC19_t       date            = 0;
    int             dayOfWeek       = 0;
    Time_t          timeHHMM        = 2400;
    struct tm       localTm         = { 0 };

    CsDbg( CD_DEBUG, "MYKI_CD:getProducts" );

    if ( time == TIME_NOT_SET )
    {
        CsErrx( "MYKI_CD:getProducts : time not set" );
        return  false;
    }

    /*  Creates an empty "products" array */
    products[ "products" ]  = Json::Value( Json::arrayValue );

    localtime_r( (time_t*)&time, &localTm );
    date        = mkdate( &localTm );
    dayOfWeek   = ( localTm.tm_wday == 0 /*SUNDAY*/ ? MYKI_CD_DOW_SUNDAY : localTm.tm_wday );
    timeHHMM    = ( localTm.tm_hour * 100 ) + localTm.tm_min;

    try
    {
        std::stringstream   query1;
        std::string         query;
        const char         *pQuery          = NULL;
        Rows                productRecords;
        DbAccess           *m_dbAccess      = getDBAccess();

        if ( m_dbAccess == NULL )
        {
            /*  Failed opening Tariff database */
            throw   __LINE__;
        }

        /*  Retrieves all products matching given product type */
        query1  << "SELECT  * "
                   "FROM    ProductRecord "
                   "WHERE   ProductRecord.fk_major_version= " << getCurrentCDMajorVersion() << " "
                       "AND ProductRecord.fk_minor_version= " << getCurrentCDMinorVersion() << " ";
        if ( productType != NULL )
        {
            query1  << "AND ProductRecord.type LIKE '" << productType << "' ";
        }
        query   = query1.str();
        pQuery  = query.c_str();
        if ( m_dbAccess->executeSqlQuery( pQuery, productRecords ) != SQLITE_OK )
        {
            /*  Failed executing query */
            throw   __LINE__;
        }

        for ( Rows::const_iterator itrProduct = productRecords.begin();
                itrProduct != productRecords.end();
                ++itrProduct )
        {
            const ColumnValue  &productRecord           = *itrProduct;
            std::string         productPK               = productRecord[ "PrimaryKey" ];
            std::string         productType             = productRecord[ "type"       ];
            std::stringstream   query2;
            Rows                attrRecords;
            bool                allowSalesChannel       = false;
            bool                allowServiceProvider    = false;
            bool                allowStartDate          = productType == "ThirdParty" ? true : false;
            bool                allowEndDate            = productType == "ThirdParty" ? true : false;
            bool                allowDayOfWeek          = false;
            bool                allowTime               = false;
            bool                allowSaleZone           = false;
            std::string         PLU;
            U32_t               productPrice            = 0;
            bool                GSTApplicable           = false;

            /*  Retrieves all default and specific attribute name/value pairs */
            query2  << "SELECT      1 AS is_default, name, value "
                       "FROM        ProductDefaultAttribute "
                       "WHERE       ProductDefaultAttribute.FK_ProductRecord=" << productPK << " "
                       "UNION "
                       "SELECT      0 AS is_default, name, value "
                       "FROM        ProductAttribute "
                       "WHERE       ProductAttribute.FK_ProductRecord=" << productPK << " "
                       "ORDER   BY  name, is_default DESC ";
            query   = query2.str();
            pQuery  = query.c_str();
            if ( m_dbAccess->executeSqlQuery( pQuery, attrRecords ) != SQLITE_OK )
            {
                /*  Failed executing query */
                throw   __LINE__;
            }

            /*  Performs validity check on saleable product */
            for ( Rows::const_iterator itrAttr = attrRecords.begin();
                    itrAttr != attrRecords.end();
                    ++itrAttr )
            {
                const ColumnValue  &attrRecord  = *itrAttr;
                std::string         attrName    = attrRecord[ "name"  ];
                std::string         attrValue   = attrRecord[ "value" ];
                const char         *pAttrName   = attrName.c_str();
                const char         *pAttrValue  = attrValue.c_str();

                if      ( attrName == "SalesChannel"    )   { checkProductIncluded(          allowSalesChannel,    deviceType,        attrValue ); }
                else if ( attrName == "ServiceProvider" )   { checkProductIncluded(          allowServiceProvider, serviceProviderId, attrValue ); }
                else if ( attrName == "SalesZone"       )   { checkProductIncluded(          allowSaleZone,        zone,              attrValue ); }
                else if ( attrName == "StartDate"       )   { checkProductIncludedStartDate( allowStartDate,       date,              attrValue ); }
                else if ( attrName == "EndDate"         )   { checkProductIncludedEndDate(   allowEndDate,         date,              attrValue ); }
                else if ( attrName == "DayOfWeek"       )   { checkProductIncluded(          allowDayOfWeek,       dayOfWeek,         attrValue ); }
                else if ( attrName == "TimeOfDay"       )   { checkProductIncludedTime(      allowTime,            timeHHMM,          attrValue ); }
                else if ( attrName == "PLU"             )   { PLU           =                                                         attrValue  ; }
                else if ( attrName == "Price"           )   { productPrice  = convertStringToU32(                                     attrValue ); }
                else if ( attrName == "GSTApplicable"   )   { GSTApplicable = convertStringToBool(                                    attrValue ); }
            }

            if      ( allowSalesChannel    == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : excluded device type"       ); }
            else if ( allowServiceProvider == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : excluded service provider"  ); }
            else if ( allowSaleZone        == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : excluded sales zone"        ); }
            else if ( allowStartDate       == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : not yet available"          ); }
            else if ( allowEndDate         == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : no longer available"        ); }
            else if ( allowDayOfWeek       == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : not available on this day"  ); }
            else if ( allowTime            == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : not available at this time" ); }
            else if ( productPrice         == 0     ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : zero product price"         ); }
            else
            {
                Json::Value     productValue;
                std::string     productId           = productRecord[ "id" ];
                std::string     productShortDesc    = productRecord[ "short_desc" ];

                CsDbg( CD_DEBUG, "MYKI_CD:getProducts : Add '%d-%s'",
                        productId.c_str(),
                        productShortDesc.c_str() );

                /*  Creates saleable product object */
                productValue[ "id"            ] = convertStringToU32( productRecord[ "id"        ] );
                productValue[ "issuer_id"     ] = convertStringToU32( productRecord[ "issuer_id" ] );
                productValue[ "type"          ] = productRecord[ "type"       ];
                productValue[ "subtype"       ] = productRecord[ "subtype"    ];
                productValue[ "short_desc"    ] = productRecord[ "short_desc" ];
                productValue[ "long_desc"     ] = productRecord[ "long_desc"  ];
                if ( PLU.empty() == false )
                {
                    productValue[ "PLU"       ] = PLU;
                }
                productValue[ "Price"         ] = productPrice;
                productValue[ "GSTApplicable" ] = GSTApplicable;

                /*  And adds to saleable product list */
                products[ "products" ].append( productValue );
            }
        }
        returnValue = true;
    }
    catch ( int e )
    {
        /*  Failed accessing Tariff database */
        returnValue = false;
    }

    CsDbg( CD_DEBUG, "MYKI_CD:getProducts returns %s", returnValue == false ? "FALSE" : "TRUE" );
    return  returnValue;
}