签到规则工具(1)
package com.js.ai.modules.pointwall.util; import java.util.Calendar; import java.util.Date; /** * * @ClassName: SignRule * @Description: TODO 用户签到规则 * @author: * @date: */ public class SignRule { /** * 移位 * @param oldHistory * @param moveAmount * @return */ public static long moveByte(long oldHistory,long moveAmount){ long moveResult = oldHistory<<moveAmount; long result=Long.parseLong(toFullBinaryString(moveResult), 2)+1; return result; } public static String toFullBinaryString(long num){ final int size=42; char[] chs = new char[size]; for(int i = 0; i < size; i++) { chs[size - 1 - i] = (char)(((num >> i) & 1) + '0'); } return new String(chs); } /** * * @Title: getScoreByRule * @Description: TODO 连续签到3天获得10积分 连续签到7天获得20积分,连续签到15天获得50积分,连续签到 30天获得120积分 * @param signCount * @return * @return: int */ public static int getScoreByRule(int signCount) { int addScore=0; if(signCount==3){ addScore=10; }else if(signCount==7){ addScore=20; }else if(signCount==15){ addScore=50; }else if (signCount>=30){ addScore=120; } return addScore; } /** * 获取当天的起始时间 * @param oldTime * @param newTime */ public static Date getTodayStartTime(){ Date now=new Date(); Calendar calendar=Calendar.getInstance(); calendar.setTime(now); calendar.set(Calendar.HOUR_OF_DAY,0); calendar.set(Calendar.MINUTE,0); calendar.set(Calendar.SECOND,0); calendar.set(Calendar.MILLISECOND,0); Date startTime=calendar.getTime(); return startTime; } /** * * @Title: daysOfTwo * @Description: TODO 两个日期相减获得的天数 * @param fDate * @param oDate * @return * @return: int */ public static int daysOfTwo(Date fDate, Date oDate) { Calendar aCalendar = Calendar.getInstance(); aCalendar.setTime(fDate); int day1 = aCalendar.get(Calendar.DAY_OF_YEAR); aCalendar.setTime(oDate); int day2 = aCalendar.get(Calendar.DAY_OF_YEAR); return day2 - day1; } }