Skip to content

Commit

Permalink
moar date formats,
Browse files Browse the repository at this point in the history
added warning to date columns if user has date only format selected
  • Loading branch information
mukunku committed Aug 13, 2022
1 parent e1187ff commit 8761da3
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/ParquetFileViewer/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class AppSettings
private const string AutoSizeColumnsModeKey = "AutoSizeColumnsMode";
private const string DateTimeDisplayFormatKey = "DateTimeDisplayFormat";

//TODO: Cleanup this setting after sufficient time has passed.
[Obsolete($"We have more date formats now so use {nameof(DateTimeDisplayFormat)} instead.")]
public static bool UseISODateFormat
{
Expand Down Expand Up @@ -57,7 +58,6 @@ public static DateFormat DateTimeDisplayFormat
if (value is null)
{
//Fallback to legacy site setting until everyone switches over to this new site setting
//TODO: Cleanup this fallback after sufficient time has passed.
var useIsoFormat = false;
if (bool.TryParse(registryKey.GetValue(UseISODateFormatKey)?.ToString(), out useIsoFormat))
{
Expand Down
3 changes: 2 additions & 1 deletion src/ParquetFileViewer/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum DateFormat
Default_DateOnly,
ISO8601,
ISO8601_DateOnly,
ISO8601_Alt1
ISO8601_Alt1,
ISO8601_Alt2
}
}
18 changes: 17 additions & 1 deletion src/ParquetFileViewer/Helpers/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace ParquetFileViewer.Helpers
{
public static class ExtensionMethods
{
private const string DefaultDateTimeFormat = "g";
private const string DateOnlyDateTimeFormat = "d";
private const string ISO8601DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fffZ";
private const string ISO8601DateOnlyFormat = "yyyy-MM-dd";
private const string ISO8601Alt1DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
private const string ISO8601Alt2DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

/// <summary>
/// Returns a list of all column names within a given datatable
Expand Down Expand Up @@ -36,7 +38,21 @@ public static IList<string> GetColumnNames(this DataTable datatable)
DateFormat.ISO8601_DateOnly => ISO8601DateOnlyFormat,
DateFormat.Default_DateOnly => DateOnlyDateTimeFormat,
DateFormat.ISO8601_Alt1 => ISO8601Alt1DateTimeFormat,
DateFormat.Default or _ => null,
DateFormat.ISO8601_Alt2 => ISO8601Alt2DateTimeFormat,
DateFormat.Default => DefaultDateTimeFormat,
_ => null
};

/// <summary>
/// Returns true if the date format does not contain a time component
/// </summary>
/// <param name="dateFormat">Date format to check</param>
/// <returns>True if the date format has time information</returns>
public static bool IsDateOnlyFormat(this DateFormat dateFormat) => dateFormat switch
{
DateFormat.ISO8601_DateOnly => true,
DateFormat.Default_DateOnly => true,
_ => false
};
}
}
34 changes: 24 additions & 10 deletions src/ParquetFileViewer/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 61 additions & 14 deletions src/ParquetFileViewer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private string OpenFilePath
}
else
{
this.Text = string.Concat("Open File: ", value);
this.Text = string.Concat($"File: ", value);
this.changeFieldsMenuStripButton.Enabled = true;
this.saveAsToolStripMenuItem.Enabled = true;
this.getSQLCreateTableScriptToolStripMenuItem.Enabled = true;
Expand Down Expand Up @@ -135,6 +135,8 @@ private DataTable MainDataSource
}
private Panel loadingPanel = null;
private Parquet.Data.Schema openFileSchema;

private ToolTip dateOnlyFormatWarningToolTip = new ToolTip();
#endregion

public MainForm()
Expand Down Expand Up @@ -378,22 +380,41 @@ private void userGuideToolStripMenuItem_Click(object sender, EventArgs e)

private void MainGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex < 0 || e.ColumnIndex < 0)
return;

if (e.Value == null || e.Value == DBNull.Value)
//Add warnings to date field headers if the user is using a "Date Only" date format.
//We want to be helpful so people don't accidentally leave a date only format on and think they are missing time information in their data.
if (e.RowIndex == -1 && e.ColumnIndex >= 0)
{
bool isDateTimeCell = ((DataGridView)sender).Columns[e.ColumnIndex].ValueType == typeof(DateTime);
bool isUserUsingDateOnlyFormat = AppSettings.DateTimeDisplayFormat.IsDateOnlyFormat();
if (isDateTimeCell && isUserUsingDateOnlyFormat)
{
var img = Properties.Resources.exclamation_icon_yellow;
Rectangle r1 = new Rectangle(e.CellBounds.Left + e.CellBounds.Width - img.Width, 4, img.Width, img.Height);
Rectangle r2 = new Rectangle(0, 0, img.Width, img.Height);
string header = ((DataGridView)sender).Columns[e.ColumnIndex].HeaderText;
e.PaintBackground(e.CellBounds, true);
e.PaintContent(e.CellBounds);
e.Graphics.DrawImage(img, r1, r2, GraphicsUnit.Pixel);

e.Handled = true;
}
}
else if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
e.Paint(e.CellBounds, DataGridViewPaintParts.All
& ~(DataGridViewPaintParts.ContentForeground));
if (e.Value == null || e.Value == DBNull.Value)
{
e.Paint(e.CellBounds, DataGridViewPaintParts.All
& ~(DataGridViewPaintParts.ContentForeground));

var font = new Font(e.CellStyle.Font, FontStyle.Italic);
var color = SystemColors.ActiveCaptionText;
if (this.mainGridView.SelectedCells.Contains(((DataGridView)sender)[e.ColumnIndex, e.RowIndex]))
color = Color.White;
var font = new Font(e.CellStyle.Font, FontStyle.Italic);
var color = SystemColors.ActiveCaptionText;
if (this.mainGridView.SelectedCells.Contains(((DataGridView)sender)[e.ColumnIndex, e.RowIndex]))
color = Color.White;

TextRenderer.DrawText(e.Graphics, "NULL", font, e.CellBounds, color, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
TextRenderer.DrawText(e.Graphics, "NULL", font, e.CellBounds, color, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);

e.Handled = true;
e.Handled = true;
}
}
}

Expand Down Expand Up @@ -670,7 +691,6 @@ private void ReadDataBackgroundWorker_RunWorkerCompleted(object sender, RunWorke
}

var result = (ParquetReadResult)e.Result;
result.Result.Rows[0][1] = new DateTime(2000, 1, 1, 0, 0, 0, 0);
this.recordCountStatusBarLabel.Text = string.Format("{0} to {1}", this.CurrentOffset, this.CurrentOffset + result.Result.Rows.Count);
this.totalRowCountStatusBarLabel.Text = result.TotalNumberOfRecordsInFile.ToString();
this.actualShownRecordCountLabel.Text = result.Result.Rows.Count.ToString();
Expand Down Expand Up @@ -1058,5 +1078,32 @@ private void changeColumnSizingToolStripMenuItem_Click(object sender, EventArgs
this.ShowError(ex);
}
}

private void mainGridView_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 && e.ColumnIndex >= 0)
{
bool isDateTimeCell = ((DataGridView)sender).Columns[e.ColumnIndex].ValueType == typeof(DateTime);
bool isUserUsingDateOnlyFormat = AppSettings.DateTimeDisplayFormat.IsDateOnlyFormat();
if (isDateTimeCell && isUserUsingDateOnlyFormat)
{
var relativeMousePosition = this.PointToClient(Cursor.Position);
this.dateOnlyFormatWarningToolTip.Show($"Date only format enabled. To see time values: Edit -> Date Format",
this, relativeMousePosition, 10000);
}
}
}

private void mainGridView_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
this.dateOnlyFormatWarningToolTip.Hide(this);
}

private int mouseLastX, mouseLastY;
private void MainForm_MouseMove(object sender, MouseEventArgs e)
{
mouseLastX = e.X;
mouseLastY = e.Y;
}
}
}
14 changes: 13 additions & 1 deletion src/ParquetFileViewer/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/ParquetFileViewer/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<data name="exclamation_icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\exclamation_icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="exclamation_icon_yellow" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\exclamation_icon_yellow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="hourglass" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\hourglass.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Utilities/Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Apache.Arrow" Version="8.0.0" />
<PackageReference Include="Apache.Arrow" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Parquet.Net" Version="3.9.1" />
</ItemGroup>
Expand Down

0 comments on commit 8761da3

Please sign in to comment.