All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.thunderz99.cosmos.util.TimestampUtil Maven / Gradle / Ivy

There is a newer version: 0.7.11
Show newest version
package io.github.thunderz99.cosmos.util;

import java.util.Map;

import org.apache.commons.collections4.MapUtils;

/**
 * A simple util class used to convert double timestamp to int timestamp in map
 */
public class TimestampUtil {

    /**
     * convert _ts field in map from Double to Long for compatibility of cosmosdb and mongodb
     *
     * 

* cosmosdb uses Long _ts * mongodb uses Double _ts for sort stability *

* * @param map */ public static void processTimestampPrecision(Map map) { if (MapUtils.isEmpty(map)) { return; } var ts = map.get("_ts"); if (ts == null) { // do nothing return; } if (ts instanceof Double) { //for compatibility, convert 1714546148.123d to 1714546148L map.put("_ts", ((Double) ts).longValue()); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy