-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix bug * lint fixes
- Loading branch information
Connor Bechthold
authored
Sep 27, 2023
1 parent
8cb1d23
commit 91d7519
Showing
8 changed files
with
142 additions
and
29 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
backend/migrations/versions/24fad25f60e3_update_resident_date_fields.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""update_resident_date_fields | ||
Revision ID: 24fad25f60e3 | ||
Revises: a5d22b31faab | ||
Create Date: 2023-09-26 19:33:15.491168 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "24fad25f60e3" | ||
down_revision = "a5d22b31faab" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("residents", schema=None) as batch_op: | ||
batch_op.alter_column( | ||
"date_joined", | ||
existing_type=postgresql.TIMESTAMP(timezone=True), | ||
type_=sa.Date(), | ||
existing_nullable=False, | ||
) | ||
batch_op.alter_column( | ||
"date_left", | ||
existing_type=postgresql.TIMESTAMP(timezone=True), | ||
type_=sa.Date(), | ||
existing_nullable=True, | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("residents", schema=None) as batch_op: | ||
batch_op.alter_column( | ||
"date_left", | ||
existing_type=sa.Date(), | ||
type_=postgresql.TIMESTAMP(timezone=True), | ||
existing_nullable=True, | ||
) | ||
batch_op.alter_column( | ||
"date_joined", | ||
existing_type=sa.Date(), | ||
type_=postgresql.TIMESTAMP(timezone=True), | ||
existing_nullable=False, | ||
) | ||
|
||
# ### end Alembic commands ### |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Combine date and time | ||
export const combineDateTime = (dateObj: Date, timeStr: string): Date => { | ||
// Extract time components from timeStr | ||
const [hours, minutes] = timeStr.split(":").map(Number); | ||
|
||
// Create a new Date object with the combined date and time | ||
const newDateObj = new Date(dateObj); | ||
newDateObj.setHours(hours); | ||
newDateObj.setMinutes(minutes); | ||
|
||
return newDateObj; | ||
}; | ||
|
||
/** | ||
* | ||
* @param dateString yyyy-mm-dd format | ||
*/ | ||
export const convertToDate = (dateString: string): Date => { | ||
// Split the date string into its components | ||
const dateComponents = dateString.split("-"); | ||
const year = parseInt(dateComponents[0], 10); | ||
const month = parseInt(dateComponents[1], 10) - 1; // Months are zero-based (0-11) | ||
const day = parseInt(dateComponents[2], 10); | ||
|
||
// Create a Date object using the components | ||
return new Date(year, month, day); | ||
}; | ||
|
||
/** | ||
* | ||
* @returns date string in yyyy-mm-dd format | ||
*/ | ||
export const convertToString = (date: Date): string => { | ||
// Get the year, month, and day components | ||
const year = date.getFullYear(); | ||
const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-based, so add 1 | ||
const day = String(date.getDate()).padStart(2, "0"); | ||
|
||
return `${year}-${month}-${day}`; | ||
}; |