Created
March 18, 2020 15:45
-
-
Save timvw/4d8a738b364e2d4bc896f6021be2bdc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#set -x | |
partitions_between() { | |
local from=$1 | |
local to=$2 | |
local offset_in_seconds=$3 | |
local fmt=$4 | |
current=$from | |
while [ $current -lt $to ]; | |
do | |
echo $(eval date -d "@$current" $fmt) | |
current=$(expr $current + $offset_in_seconds) | |
done | |
} | |
daily_partitions_between() { | |
partitions_between $1 $2 86400 '+%Y/%m/%d' | |
} | |
hourly_partitions_between() { | |
partitions_between $1 $2 3600 '+%Y/%m/%d/%H' | |
} | |
from=$(date -d "2019/12/18 10:00:00" +%s) | |
to=$(date -d "-1 hour" +%s) | |
for p in $(hourly_partitions_between $from $to); | |
do | |
echo $p | |
done | |
daily_partitions_between $(date -d "3 days ago" +%s) $to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment