zoukankan      html  css  js  c++  java
  • 签到规则工具(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;
    
    		    }
    }
    

      

  • 相关阅读:
    LOJ 6089 小Y的背包计数问题 —— 前缀和优化DP
    洛谷 P1969 积木大赛 —— 水题
    洛谷 P1965 转圈游戏 —— 快速幂
    洛谷 P1970 花匠 —— DP
    洛谷 P1966 火柴排队 —— 思路
    51Nod 1450 闯关游戏 —— 期望DP
    洛谷 P2312 & bzoj 3751 解方程 —— 取模
    洛谷 P1351 联合权值 —— 树形DP
    NOIP2007 树网的核
    平面最近点对(加强版)
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6744999.html
Copyright © 2011-2022 走看看