Java Code Examples for org.apache.calcite.avatica.util.DateTimeUtils#floorMod()
The following examples show how to use
org.apache.calcite.avatica.util.DateTimeUtils#floorMod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlFunctions.java From Quicksql with MIT License | 6 votes |
public static int subtractMonths(long t0, long t1) { final long millis0 = DateTimeUtils.floorMod(t0, DateTimeUtils.MILLIS_PER_DAY); final int d0 = (int) DateTimeUtils.floorDiv(t0 - millis0, DateTimeUtils.MILLIS_PER_DAY); final long millis1 = DateTimeUtils.floorMod(t1, DateTimeUtils.MILLIS_PER_DAY); final int d1 = (int) DateTimeUtils.floorDiv(t1 - millis1, DateTimeUtils.MILLIS_PER_DAY); int x = subtractMonths(d0, d1); final long d2 = addMonths(d1, x); if (d2 == d0 && millis0 < millis1) { --x; } return x; }
Example 2
Source File: SqlFunctionUtils.java From flink with Apache License 2.0 | 6 votes |
public static int addMonths(int date, int m) { int y0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.YEAR, date); int m0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.MONTH, date); int d0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.DAY, date); m0 += m; int deltaYear = (int) DateTimeUtils.floorDiv(m0, 12); y0 += deltaYear; m0 = (int) DateTimeUtils.floorMod(m0, 12); if (m0 == 0) { y0 -= 1; m0 += 12; } int last = lastDay(y0, m0); if (d0 > last) { d0 = last; } return DateTimeUtils.ymdToUnixDate(y0, m0, d0); }
Example 3
Source File: SqlFunctionUtils.java From flink with Apache License 2.0 | 6 votes |
public static int subtractMonths(long t0, long t1) { final long millis0 = DateTimeUtils.floorMod(t0, DateTimeUtils.MILLIS_PER_DAY); final int d0 = (int) DateTimeUtils.floorDiv(t0 - millis0, DateTimeUtils.MILLIS_PER_DAY); final long millis1 = DateTimeUtils.floorMod(t1, DateTimeUtils.MILLIS_PER_DAY); final int d1 = (int) DateTimeUtils.floorDiv(t1 - millis1, DateTimeUtils.MILLIS_PER_DAY); int x = subtractMonths(d0, d1); final long d2 = addMonths(d1, x); if (d2 == d0 && millis0 < millis1) { --x; } return x; }
Example 4
Source File: SqlFunctions.java From calcite with Apache License 2.0 | 6 votes |
/** Adds a given number of months to a date, represented as the number of * days since the epoch. */ public static int addMonths(int date, int m) { int y0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.YEAR, date); int m0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.MONTH, date); int d0 = (int) DateTimeUtils.unixDateExtract(TimeUnitRange.DAY, date); m0 += m; int deltaYear = (int) DateTimeUtils.floorDiv(m0, 12); y0 += deltaYear; m0 = (int) DateTimeUtils.floorMod(m0, 12); if (m0 == 0) { y0 -= 1; m0 += 12; } int last = lastDay(y0, m0); if (d0 > last) { d0 = last; } return DateTimeUtils.ymdToUnixDate(y0, m0, d0); }
Example 5
Source File: SqlFunctions.java From calcite with Apache License 2.0 | 6 votes |
public static int subtractMonths(long t0, long t1) { final long millis0 = DateTimeUtils.floorMod(t0, DateTimeUtils.MILLIS_PER_DAY); final int d0 = (int) DateTimeUtils.floorDiv(t0 - millis0, DateTimeUtils.MILLIS_PER_DAY); final long millis1 = DateTimeUtils.floorMod(t1, DateTimeUtils.MILLIS_PER_DAY); final int d1 = (int) DateTimeUtils.floorDiv(t1 - millis1, DateTimeUtils.MILLIS_PER_DAY); int x = subtractMonths(d0, d1); final long d2 = addMonths(d1, x); if (d2 == d0 && millis0 < millis1) { --x; } return x; }
Example 6
Source File: SqlFunctions.java From Quicksql with MIT License | 5 votes |
/** Adds a given number of months to a timestamp, represented as the number * of milliseconds since the epoch. */ public static long addMonths(long timestamp, int m) { final long millis = DateTimeUtils.floorMod(timestamp, DateTimeUtils.MILLIS_PER_DAY); timestamp -= millis; final long x = addMonths((int) (timestamp / DateTimeUtils.MILLIS_PER_DAY), m); return x * DateTimeUtils.MILLIS_PER_DAY + millis; }
Example 7
Source File: SqlFunctionUtils.java From flink with Apache License 2.0 | 5 votes |
/** TODO: remove addMonths and subtractMonths if CALCITE-3881 fixed. * https://issues.apache.org/jira/browse/CALCITE-3881 **/ public static long addMonths(long timestamp, int m) { final long millis = DateTimeUtils.floorMod(timestamp, DateTimeUtils.MILLIS_PER_DAY); timestamp -= millis; final long x = addMonths((int) (timestamp / DateTimeUtils.MILLIS_PER_DAY), m); return x * DateTimeUtils.MILLIS_PER_DAY + millis; }
Example 8
Source File: SqlFunctions.java From calcite with Apache License 2.0 | 5 votes |
/** Adds a given number of months to a timestamp, represented as the number * of milliseconds since the epoch. */ public static long addMonths(long timestamp, int m) { final long millis = DateTimeUtils.floorMod(timestamp, DateTimeUtils.MILLIS_PER_DAY); timestamp -= millis; final long x = addMonths((int) (timestamp / DateTimeUtils.MILLIS_PER_DAY), m); return x * DateTimeUtils.MILLIS_PER_DAY + millis; }