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

[fix] makeDateTrunc calculating rolling_month wrong #52579

Merged
merged 2 commits into from May 30, 2023
Merged

Conversation

kopancek
Copy link
Contributor

@kopancek kopancek commented May 30, 2023

Also fixed the function returning a string without a timezone, when it always returns times in UTC. This is done by explicitly casting to timestamptz by using TIMEZONE('UTC', ...) function.

Added unit tests as well, to make sure everything works as expected.

Test plan

Unit tests

Also fixed the function returning a string without a timezone,
when it always returns times in UTC. This is done by adding 'Z'
at the end of the date string.

Added unit tests as well, to make sure everything works as expected.
@kopancek kopancek requested review from dadlerj, nathan-downs and a team May 30, 2023 08:16
@cla-bot cla-bot bot added the cla-signed label May 30, 2023
@kopancek kopancek self-assigned this May 30, 2023
Copy link
Contributor

@sashaostrikov sashaostrikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

// by the unit parameter (e.g. day, week, month, or rolling month [prior 1 month]).
// Note: If unit is 'week', the function will truncate to the preceding Sunday.
// This is because some locales start the week on Sunday, unlike the Postgres default
// (and many parts of the world) which start the week on Monday.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and many parts of the world 😁😁😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked Cody to generate that, so shifting blame to it 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nono, liked that part, actually :)

@@ -2027,3 +2027,80 @@ func TestEventLogs_AggregatedRepoMetadataStats(t *testing.T) {
})
}
}

func TestMakeDateTruncExpression(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the tests!

Comment on lines 2102 to 2103

require.Equal(t, tc.expected, date)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use assert here so that we always run all the test cases and accumulate all the errors instead of short-circuiting the test with the first failure.

Suggested change
require.Equal(t, tc.expected, date)
assert.Equal(t, tc.expected, date)

Copy link
Contributor Author

@kopancek kopancek May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, I was not aware of that behavior.

It was actually running all the tests before for me even with require.Equal. Just that each test case failed on the first failure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, assert functions effectively call t.Errorf, require functions call t.FailNow()

@kopancek kopancek merged commit 6d2a71e into main May 30, 2023
12 of 13 checks passed
@kopancek kopancek deleted the milan/fix_date_trunc branch May 30, 2023 12:01
@github-actions
Copy link
Contributor

The backport to 5.0 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-5.0 5.0
# Navigate to the new working tree
cd .worktrees/backport-5.0
# Create a new branch
git switch --create backport-52579-to-5.0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 6d2a71eb07b885346b677eee150930abb7e8910f
# Push it to GitHub
git push --set-upstream origin backport-52579-to-5.0
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.0

Then, create a pull request where the base branch is 5.0 and the compare/head branch is backport-52579-to-5.0.

@github-actions github-actions bot added backports failed-backport-to-5.0 release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases labels May 30, 2023
kopancek added a commit that referenced this pull request May 31, 2023
Also fixed the function returning a string without a timezone, when it
always returns times in UTC. This is done by explicitly casting to
timestamptz by using `TIMEZONE('UTC', ...)` function.

Added unit tests as well, to make sure everything works as expected.

Unit tests

(cherry picked from commit 6d2a71e)
keegancsmith pushed a commit that referenced this pull request May 31, 2023
…52579) (#52607)

Backport of #52579

(cherry picked from commit 6d2a71e)

## Test plan

tested in upstream main PR
ErikaRS pushed a commit that referenced this pull request Jun 22, 2023
Also fixed the function returning a string without a timezone, when it
always returns times in UTC. This is done by explicitly casting to
timestamptz by using `TIMEZONE('UTC', ...)` function.

Added unit tests as well, to make sure everything works as expected.

## Test plan

Unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backports cla-signed release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants