Skip to content

Instantly share code, notes, and snippets.

@timvw
Created March 18, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timvw/4d8a738b364e2d4bc896f6021be2bdc2 to your computer and use it in GitHub Desktop.
Save timvw/4d8a738b364e2d4bc896f6021be2bdc2 to your computer and use it in GitHub Desktop.
#!/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