Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Date Masking Buitlin Algorithm | Keep Year Only #29257

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.apache.shardingsphere.mask.algorithm.replace;

import org.apache.commons.lang3.time.DateUtils;
import org.apache.shardingsphere.mask.spi.MaskAlgorithm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateKeepYearOnlyAlgorithm implements MaskAlgorithm<Object, Date> {
Afsalmc marked this conversation as resolved.
Show resolved Hide resolved
@Override
public Date mask(Object plainValue) {
java.sql.Date result = null == plainValue ? null : (java.sql.Date)plainValue;
if(null == plainValue){
return result;
}
Calendar cal = new GregorianCalendar();
cal.setTime(result);
cal.set(Calendar.DAY_OF_YEAR,1); // Remove Month and Day information from the Value.
return new java.sql.Date(cal.getTime().getTime());
}
@Override
public String getType() {
return "DATE_KEEP_YEAR_ONLY";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ org.apache.shardingsphere.mask.algorithm.cover.MaskBeforeSpecialCharsAlgorithm
org.apache.shardingsphere.mask.algorithm.cover.MaskFirstNLastMMaskAlgorithm
org.apache.shardingsphere.mask.algorithm.cover.MaskFromXToYMaskAlgorithm
org.apache.shardingsphere.mask.algorithm.replace.GenericTableRandomReplaceAlgorithm
org.apache.shardingsphere.mask.algorithm.cover.DateKeepYearOnlyAlgorithm
Loading