在附件中,我需要员工以(HH:MM AM/PM)
格式手动输入登录和注销时间。在E栏中,我需要一个公式来计算其间的持续时间和小时数。
我尝试使用=text(D2-C2,"h:mm")
公式,当我将所有列应用于所有列时,它们会使用现有的空单元格进行更新,并在E列中生成00:00。
我只需要在更新C和D列值时更新E列。
有人可以帮我这方面吗?我需要时间框架作为12小时格式。
答案 0 :(得分:1)
您只能在=IF(AND(C1<>"",D1<>""),D1-C1,"")
列中使用No Of Hours
来计算填充Log In Time
和Log Out Time
。
对于格式设置,您可以对Custom Format
列使用h:mm
- No Of Hours
。
答案 1 :(得分:1)
1,尽量不要将实时转换为文本。
在F2中使用此公式然后填写。 dow <- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
set.seed(2)
df <- data.frame(Day_of_week = sample(7, size=20, replace=TRUE))
head(df)
# Day_of_week
# 1 2
# 2 5
# 3 5
# 4 2
# 5 7
# 6 7
df$Day_of_week <- dow[df$Day_of_week]
head(df)
# Day_of_week
# 1 Monday
# 2 Thursday
# 3 Thursday
# 4 Monday
# 5 Saturday
# 6 Saturday
如果班次跨越午夜,这也应该有用。
在单元格上使用此自定义数字格式import liquibase.change.core.AddColumnChange;
import liquibase.change.core.CreateTableChange;
import liquibase.change.core.RenameColumnChange;
import liquibase.change.core.RenameTableChange;
import liquibase.changelog.ChangeLogParameters;
import liquibase.changelog.ChangeSet;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.exception.ChangeLogParseException;
import liquibase.parser.core.yaml.YamlChangeLogParser;
import liquibase.resource.FileSystemResourceAccessor;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class LiquibaseScriptsTest {
public static final String LIQUIBASE_FILES_LOCATION = "src/main/resources/db/changelog/changes/*.yml";
public static final int NB_LAST_FILES_TO_CHECK = 5;
private static final int ORACLE_TABLE_NAME_MAX_LENGTH = 30;
private static final int ORACLE_COLUMN_NAME_MAX_LENGTH = 30;
private List<DatabaseChangeLog> scriptsToCheck;
private final static Comparator<Resource> resourceComparator = (r1, r2) -> r1.getFilename().compareTo(r2.getFilename());
private static YamlChangeLogParser parser = new YamlChangeLogParser();
@Before
public void setUp() throws IOException {
ResourcePatternResolver resourceFinder = new PathMatchingResourcePatternResolver(this.getClass().getClassLoader());
Resource[] resources = resourceFinder.getResources("file:" + LIQUIBASE_FILES_LOCATION);
scriptsToCheck = Arrays.asList(resources).stream()
//looking only at the latest files, assuming their name is indexed
.sorted(resourceComparator.reversed())
.limit(NB_LAST_FILES_TO_CHECK)
.map(r -> toLiquibaseScript(r))
.collect(toList());
}
@Test
public void someScriptsAreChecked() {
assertThat(scriptsToCheck).as("There's no script to check - are you sure you configured the path correctly ? ").isNotEmpty();
assertThat(scriptsToCheck.size()).isLessThanOrEqualTo(NB_LAST_FILES_TO_CHECK);
}
@Test
public void tableNamesShouldBeLessThanOracleMaxSize_whenCreated() {
Stream<CreateTableChange> createTableChanges = getChangesAsStreamOf(CreateTableChange.class);
createTableChanges.forEach(tableCreationChange -> {
assertThat(tableCreationChange.getTableName().length())
.as("change " + tableCreationChange.getChangeSet().getId() + " - table name is too long - " +
tableCreationChange.getTableName() + " is " + tableCreationChange.getTableName().length() +
"char long while maximum for Oracle is " + ORACLE_TABLE_NAME_MAX_LENGTH)
.isLessThanOrEqualTo(ORACLE_TABLE_NAME_MAX_LENGTH);
});
}
@Test
public void tableNamesShouldBeLessThanOracleMaxSize_whenModified() {
Stream<RenameTableChange> renameTableChanges = getChangesAsStreamOf(RenameTableChange.class);
renameTableChanges.forEach(tableRenameChange -> {
assertThat(tableRenameChange.getNewTableName().length())
.as("change " + tableRenameChange.getChangeSet().getId() + " - table name is too long - " +
tableRenameChange.getNewTableName() + " is " + tableRenameChange.getNewTableName().length() +
"char long while maximum for Oracle is " + ORACLE_TABLE_NAME_MAX_LENGTH)
.isLessThanOrEqualTo(ORACLE_TABLE_NAME_MAX_LENGTH);
});
}
@Test
public void columnNamesShouldBeLessThanOracleMaxSize_whenCreated() {
Stream<AddColumnChange> addColumnChanges = getChangesAsStreamOf(AddColumnChange.class);
addColumnChanges.flatMap(columnCreationChanges -> columnCreationChanges.getColumns().stream())
.forEach(columnCreationChange -> {
assertThat(columnCreationChange.getName().length())
.as("column name is too long - " + columnCreationChange.getName() + " is " + columnCreationChange.getName().length() +
"char long while maximum for Oracle is " + ORACLE_COLUMN_NAME_MAX_LENGTH)
.isLessThanOrEqualTo(ORACLE_COLUMN_NAME_MAX_LENGTH);
});
}
@Test
public void columnNamesShouldBeLessThanOracleMaxSize_whenModified() {
Stream<RenameColumnChange> renameColumnChanges = getChangesAsStreamOf(RenameColumnChange.class);
renameColumnChanges.forEach(columnRenameChange -> {
assertThat(columnRenameChange.getNewColumnName().length())
.as("column name is too long - " + columnRenameChange.getNewColumnName() + " is " +
columnRenameChange.getNewColumnName().length() + "char long while maximum for Oracle is " +
ORACLE_COLUMN_NAME_MAX_LENGTH)
.isLessThanOrEqualTo(ORACLE_COLUMN_NAME_MAX_LENGTH);
});
}
private <E> Stream<E> getChangesAsStreamOf(Class E) {
Stream<Stream<ChangeSet>> changeSets = scriptsToCheck.stream().map(script -> script.getChangeSets().stream());
Stream<ChangeSet> changeSetStream = changeSets.flatMap(changeSet -> changeSet);
return changeSetStream.flatMap(changeSet -> changeSet.getChanges().stream())
.filter(E::isInstance)
.map(change -> (E) change);
}
private DatabaseChangeLog toLiquibaseScript(Resource r) {
try {
System.out.println("going to apply checks on "+r.getFilename());
return parser.parse(r.getFile().getCanonicalPath(), new ChangeLogParameters(), new FileSystemResourceAccessor());
} catch (ChangeLogParseException | IOException e) {
fail("couldn't parse Liquibase script - " + r.getFilename() + " - " + e.getMessage());
}
return null;
}
}
。
示例: