public Value Now(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "", ErrorType.InvalidArgument); var ticks = DateTime.Now.Ticks / TimeSpan.TicksPerSecond * TimeSpan.TicksPerSecond; return(new Value(DateTimeUtility.DateTimeToString(new DateTime(ticks)))); }
public Value Average(IReadOnlyList <Value> args) { var nums = args.Where(a => a.DataType == DataType.Number).ToList(); ArgumentsVerifier.VerifyAndThrow(nums, "n+", ErrorType.InvalidArgument); return(new Value(nums.Average(n => n.Number))); }
public Value DaysInMonth(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument); var date = DateTimeUtility.ParseDateTime(args[0].String); return(new Value(DateTimeUtility.GetDaysInMonth(date.Year, date.Month))); }
public Value Logarithm10(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument); if (args[0].Number <= 0m) { throw new ErrorException(ErrorType.InvalidArgument); } return(new Value(Math.Log((double)args[0].Number, 10.0))); }
public Value Sqrt(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument); if (args[0].Number < 0m) { throw new ErrorException(ErrorType.InvalidArgument); } return(new Value(Math.Sqrt((double)args[0].Number))); }
public Value Median(IReadOnlyList <Value> args) { var nums = args.Where(x => x.DataType == DataType.Number).ToList(); ArgumentsVerifier.VerifyAndThrow(nums, "n+", ErrorType.InvalidArgument); var sorted = nums.OrderBy(n => n.Number).ToList(); var a = sorted[(sorted.Count - 1) / 2].Number / 2m; var b = sorted[(sorted.Count + 0) / 2].Number / 2m; return(new Value(a + b)); }
public Value Kyureki(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument); var date = DateTimeUtility.ParseDateTime(args[0].String); var sb = new StringBuilder(); sb.Append(DateTimeUtility.DateTimeToKyurekiString(date)); sb.Append(DateTimeUtility.TryGetEtoString(date, out var eto) ? $" {eto}" : null); sb.Append(DateTimeUtility.TryGetRokuyoString(date, out var rokuyo) ? $" {rokuyo}" : null); return(new Value(sb.ToString())); }
public Value Factorial(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument); if (args[0].Number < 0m) { throw new ErrorException(ErrorType.InvalidArgument); } var f = 1m; for (var n = args[0].Number; n > 1; n--) { f *= n; } return(new Value(f)); }
public Value Logarithm(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "nn?", ErrorType.InvalidArgument); if (args[0].Number <= 0m) { throw new ErrorException(ErrorType.InvalidArgument); } if (args.Count == 2 && args[1].Number < 0m) { throw new ErrorException(ErrorType.InvalidArgument); } if (args.Count == 2 && args[1].Number == 1m) { throw new ErrorException(ErrorType.InvalidArgument); } return((args.Count == 1) ? new Value(Math.Log((double)args[0].Number)) : new Value(Math.Log((double)args[0].Number, (double)args[1].Number))); }
public Value Sign(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument); return(new Value(Math.Sign(args[0].Number))); }
public Value Round(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "n", ErrorType.InvalidArgument); return(new Value(Math.Round(args[0].Number, MidpointRounding.AwayFromZero))); }
public Value Atan2(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "nn", ErrorType.InvalidArgument); return(new Value(Degrees(Math.Atan2((double)args[0].Number, (double)args[1].Number)))); }
public Value DayOfWeek(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument); return(new Value(DateTimeUtility.ParseDateTime(args[0].String).DayOfWeek.ToString().Substring(0, 3).ToLower())); }
public Value DayOfYear(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument); return(new Value(DateTimeUtility.ParseDateTime(args[0].String).DayOfYear)); }
public Value Weeks(IReadOnlyList <Value> args) { ArgumentsVerifier.VerifyAndThrow(args, "s", ErrorType.InvalidArgument); return(new Value(DateTimeUtility.ParseTimeSpan(args[0].String).TotalDays / 7.0)); }