- 增加 MySq 表达式解析 yyyyMMdd 常用 c# 日期格式化;

This commit is contained in:
28810 2020-05-24 02:46:19 +08:00
parent 657b3c6f43
commit 08713fba71
7 changed files with 211 additions and 61 deletions

View File

@ -41,6 +41,43 @@ namespace FreeSql.Tests.MySqlConnectorExpression
public List<TestTypeInfo> Types { get; set; }
public DateTime Time2 { get; set; }
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
g.mysql.Insert(new Topic()).ExecuteAffrows();
foreach (var dt in new[] { DateTime.Parse("2020-5-6 0:1:2"), DateTime.Parse("2020-11-16 13:21:22"), })
{
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString()));
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm")));
Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH")));
Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd")));
Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM")));
Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd")));
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("ÉÏÎç", "AM").Replace("ÏÂÎç", "PM").Replace("ÉÏ", "A").Replace("ÏÂ", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
}
}
[Fact]
public void Now()
{
@ -542,26 +579,6 @@ namespace FreeSql.Tests.MySqlConnectorExpression
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
}
[Fact]
public void DateTime_Compare()
{

View File

@ -41,6 +41,43 @@ namespace FreeSql.Tests.Odbc.MySqlExpression
public List<TestTypeInfo> Types { get; set; }
public DateTime Time2 { get; set; }
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
g.mysql.Insert(new Topic()).ExecuteAffrows();
foreach (var dt in new[] { DateTime.Parse("2020-5-6 0:1:2"), DateTime.Parse("2020-11-16 13:21:22"), })
{
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString()));
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm")));
Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH")));
Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd")));
Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM")));
Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd")));
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("ÉÏÎç", "AM").Replace("ÏÂÎç", "PM").Replace("ÉÏ", "A").Replace("ÏÂ", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
}
}
[Fact]
public void Now()
{
@ -575,26 +612,6 @@ namespace FreeSql.Tests.Odbc.MySqlExpression
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
}
[Fact]
public void DateTime_Compare()
{

View File

@ -63,6 +63,7 @@ namespace FreeSql.Tests.Odbc.SqlServerExpression
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("ÉÏÎç", "AM").Replace("ÏÂÎç", "PM").Replace("ÉÏ", "A").Replace("ÏÂ", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
}
}

View File

@ -41,6 +41,43 @@ namespace FreeSql.Tests.MySqlExpression
public List<TestTypeInfo> Types { get; set; }
public DateTime Time2 { get; set; }
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
g.mysql.Insert(new Topic()).ExecuteAffrows();
foreach (var dt in new[] { DateTime.Parse("2020-5-6 0:1:2"), DateTime.Parse("2020-11-16 13:21:22"), })
{
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), select.First(a => dt.ToString()));
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm:ss"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy-MM-dd HH:mm"), select.First(a => dt.ToString("yyyy-MM-dd HH:mm")));
Assert.Equal(dt.ToString("yyyy-MM-dd HH"), select.First(a => dt.ToString("yyyy-MM-dd HH")));
Assert.Equal(dt.ToString("yyyy-MM-dd"), select.First(a => dt.ToString("yyyy-MM-dd")));
Assert.Equal(dt.ToString("yyyy-MM"), select.First(a => dt.ToString("yyyy-MM")));
Assert.Equal(dt.ToString("yyyyMMdd"), select.First(a => dt.ToString("yyyyMMdd")));
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("ÉÏÎç", "AM").Replace("ÏÂÎç", "PM").Replace("ÉÏ", "A").Replace("ÏÂ", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
}
}
[Fact]
public void Now()
{
@ -575,25 +612,6 @@ namespace FreeSql.Tests.MySqlExpression
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_add(a__Type__Parent.`Time2`, interval (1) year) = now()))
}
[Fact]
public void this_ToString()
{
var data = new List<object>();
data.Add(select.Where(a => a.CreateTime.ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Time.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
data.Add(select.Where(a => a.Type.Parent.Time2.AddYears(1).ToString().Equals(DateTime.Now)).ToList());
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a.`Title` as4, a.`CreateTime` as5
//FROM `tb_topic111333` a
//WHERE ((date_format(a.`CreateTime`, '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type
//WHERE ((date_format(date_add(a__Type.`Time`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()));
//SELECT a.`Id` as1, a.`Clicks` as2, a.`TypeGuid` as3, a__Type.`Guid` as4, a__Type.`ParentId` as5, a__Type.`Name` as6, a__Type.`Time` as7, a.`Title` as8, a.`CreateTime` as9
//FROM `tb_topic111333` a, `TestTypeInfo333` a__Type, `TestTypeParentInfo23123` a__Type__Parent
//WHERE ((date_format(date_add(a__Type__Parent.`Time2`, interval (1) year), '%Y-%m-%d %H:%i:%s.%f') = now()))
}
[Fact]
public void DateTime_Compare()

View File

@ -71,6 +71,7 @@ namespace FreeSql.Tests.SqlServerExpression
Assert.Equal(dt.ToString("yyyyMM"), select.First(a => dt.ToString("yyyyMM")));
Assert.Equal(dt.ToString("yyyy"), select.First(a => dt.ToString("yyyy")));
Assert.Equal(dt.ToString("HH:mm:ss"), select.First(a => dt.ToString("HH:mm:ss")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h")));
Assert.Equal(dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t").Replace("ÉÏÎç", "AM").Replace("ÏÂÎç", "PM").Replace("ÉÏ", "A").Replace("ÏÂ", "P"), select.First(a => dt.ToString("yyyy MM dd HH mm ss yy M d H hh h m s tt t")));
}
}

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
namespace FreeSql.MySql
{
@ -392,7 +393,54 @@ namespace FreeSql.MySql
break;
case "Equals": return $"({left} = {args1})";
case "CompareTo": return $"timestampdiff(microsecond,{args1},{left})";
case "ToString": return exp.Arguments.Count == 0 ? $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')" : null;
case "ToString":
if (exp.Arguments.Count == 0) return $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')";
switch (args1)
{
case "'yyyy-MM-dd HH:mm:ss'": return $"date_format({left}, '%Y-%m-%d %H:%i:%s')";
case "'yyyy-MM-dd HH:mm'": return $"date_format({left}, '%Y-%m-%d %H:%i')";
case "'yyyy-MM-dd HH'": return $"date_format({left}, '%Y-%m-%d %H')";
case "'yyyy-MM-dd'": return $"date_format({left}, '%Y-%m-%d')";
case "'yyyy-MM'": return $"date_format({left}, '%Y-%m')";
case "'yyyyMMdd'": return $"date_format({left}, '%Y%m%d')";
case "'yyyyMM'": return $"date_format({left}, '%Y%m')";
case "'yyyy'": return $"date_format({left}, '%Y')";
case "'HH:mm:ss'": return $"date_format({left}, '%H:%i:%s')";
}
args1 = Regex.Replace(args1, "(yyyy|yy|MM|M|dd|d|HH|H|hh|h|mm|ss|tt)", m =>
{
switch (m.Groups[1].Value)
{
case "yyyy": return $"%Y";
case "yy": return $"%y";
case "MM": return $"%_a1";
case "M": return $"%c";
case "dd": return $"%d";
case "d": return $"%e";
case "HH": return $"%H";
case "H": return $"%k";
case "hh": return $"%h";
case "h": return $"%l";
case "mm": return $"%i";
case "ss": return $"%_a2";
case "tt": return $"%p";
}
return m.Groups[0].Value;
});
var isMatched = false;
args1 = Regex.Replace(args1, "(m|s|t)", m =>
{
isMatched = true;
switch (m.Groups[1].Value)
{
case "m": return $"'), trim(leading '0' from date_format({left}, '%i')), date_format({left}, '";
case "s": return $"'), trim(leading '0' from date_format({left}, '%s')), date_format({left}, '";
case "t": return $"'), trim(trailing 'M' from date_format({left}, '%p')), date_format({left}, '";
}
return m.Groups[0].Value;
}).Replace("%_a1", "%m").Replace("%_a2", "%s");
return isMatched == false ? $"date_format({left}, {args1})" : $"concat(date_format({left}, {args1}))".Replace($"date_format({left}, '')", "''");
}
}
return null;

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
namespace FreeSql.Odbc.MySql
{
@ -392,7 +393,54 @@ namespace FreeSql.Odbc.MySql
break;
case "Equals": return $"({left} = {args1})";
case "CompareTo": return $"timestampdiff(microsecond,{args1},{left})";
case "ToString": return exp.Arguments.Count == 0 ? $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')" : null;
case "ToString":
if (exp.Arguments.Count == 0) return $"date_format({left}, '%Y-%m-%d %H:%i:%s.%f')";
switch (args1)
{
case "'yyyy-MM-dd HH:mm:ss'": return $"date_format({left}, '%Y-%m-%d %H:%i:%s')";
case "'yyyy-MM-dd HH:mm'": return $"date_format({left}, '%Y-%m-%d %H:%i')";
case "'yyyy-MM-dd HH'": return $"date_format({left}, '%Y-%m-%d %H')";
case "'yyyy-MM-dd'": return $"date_format({left}, '%Y-%m-%d')";
case "'yyyy-MM'": return $"date_format({left}, '%Y-%m')";
case "'yyyyMMdd'": return $"date_format({left}, '%Y%m%d')";
case "'yyyyMM'": return $"date_format({left}, '%Y%m')";
case "'yyyy'": return $"date_format({left}, '%Y')";
case "'HH:mm:ss'": return $"date_format({left}, '%H:%i:%s')";
}
args1 = Regex.Replace(args1, "(yyyy|yy|MM|M|dd|d|HH|H|hh|h|mm|ss|tt)", m =>
{
switch (m.Groups[1].Value)
{
case "yyyy": return $"%Y";
case "yy": return $"%y";
case "MM": return $"%_a1";
case "M": return $"%c";
case "dd": return $"%d";
case "d": return $"%e";
case "HH": return $"%H";
case "H": return $"%k";
case "hh": return $"%h";
case "h": return $"%l";
case "mm": return $"%i";
case "ss": return $"%_a2";
case "tt": return $"%p";
}
return m.Groups[0].Value;
});
var isMatched = false;
args1 = Regex.Replace(args1, "(m|s|t)", m =>
{
isMatched = true;
switch (m.Groups[1].Value)
{
case "m": return $"'), trim(leading '0' from date_format({left}, '%i')), date_format({left}, '";
case "s": return $"'), trim(leading '0' from date_format({left}, '%s')), date_format({left}, '";
case "t": return $"'), trim(trailing 'M' from date_format({left}, '%p')), date_format({left}, '";
}
return m.Groups[0].Value;
}).Replace("%_a1", "%m").Replace("%_a2", "%s");
return isMatched == false ? $"date_format({left}, {args1})" : $"concat(date_format({left}, {args1}))".Replace($"date_format({left}, '')", "''");
}
}
return null;