public BirthdayEvent(Core core, User owner, User user, int year) : base(core) { this.owner = owner; this.user = user; if (!user.IsFriend(owner.ItemKey)) { throw new InvalidEventException(); } UnixTime tz = new UnixTime(core, user.UserInfo.TimeZoneCode); this.eventId = ~user.Id; this.subject = user.TitleNameOwnership + " birthday"; this.description = string.Empty; this.views = 0; this.attendeeCount = 0; this.ownerKey = new ItemKey(owner.Id, owner.TypeId); this.userId = user.Id; this.startTimeRaw = tz.GetUnixTimeStamp(new DateTime(year, user.Profile.DateOfBirth.Month, user.Profile.DateOfBirth.Day, 0, 0, 0)); this.endTimeRaw = tz.GetUnixTimeStamp(new DateTime(year, user.Profile.DateOfBirth.Month, user.Profile.DateOfBirth.Day, 23, 59, 59)); this.allDay = true; this.invitees = 0; this.category = 0; this.location = string.Empty; }
public static long FormDate(Core core, string name, UnixTime tz) { if (core == null) { throw new NullCoreException(); } long datetime = 0; DateTime dt = tz.Now; string dateExpression = core.Http.Form[name + "--expression"]; string timeExpression = core.Http.Form[name + "--time"]; string dateMode = core.Http.Form[name + "--mode"]; if (dateMode == "ajax" && (!string.IsNullOrEmpty(dateExpression))) { dateExpression = core.Functions.InterpretDate(dateExpression, DisplayMedium.Desktop); timeExpression = core.Functions.InterpretTime(timeExpression); string expression = dateExpression + " " + timeExpression; if (!DateTime.TryParse(expression, out dt)) { int year = core.Functions.FormInt(name + "--date-year", dt.Year); int month = core.Functions.FormInt(name + "--date-month", dt.Month); int day = core.Functions.FormInt(name + "--date-day", dt.Day); int hour = core.Functions.FormInt(name + "--date-hour", dt.Hour); int minute = core.Functions.FormInt(name + "--date-minute", dt.Minute); int second = core.Functions.FormInt(name + "--date-second", 0); dt = new DateTime(year, month, day, hour, minute, second); } } else { int year = core.Functions.FormInt(name + "--date-year", dt.Year); int month = core.Functions.FormInt(name + "--date-month", dt.Month); int day = core.Functions.FormInt(name + "--date-day", dt.Day); int hour = core.Functions.FormInt(name + "--date-hour", dt.Hour); int minute = core.Functions.FormInt(name + "--date-minute", dt.Minute); int second = core.Functions.FormInt(name + "--date-second", 0); dt = new DateTime(year, month, day, hour, minute, second); } datetime = tz.GetUnixTimeStamp(dt); return datetime; }
public List<UserRelation> GetFriendsBirthdays(long startTimeRaw, long endTimeRaw) { DateTime st = core.Tz.DateTimeFromMysql(startTimeRaw - 24 * 60 * 60); DateTime et = core.Tz.DateTimeFromMysql(endTimeRaw + 48 * 60 * 60); List<UserRelation> friends = new List<UserRelation>(); SelectQuery query = UserRelation.GetSelectQueryStub(core, UserLoadOptions.All); query.AddCondition("relation_me", userId); query.AddCondition("relation_type", "FRIEND"); query.AddCondition("profile_date_of_birth_month_cache * 31 + profile_date_of_birth_day_cache", ConditionEquality.GreaterThanEqual, st.Month * 31 + st.Day); query.AddCondition("profile_date_of_birth_month_cache * 31 + profile_date_of_birth_day_cache", ConditionEquality.LessThanEqual, et.Month * 31 + et.Day); System.Data.Common.DbDataReader friendsReader = db.ReaderQuery(query); while (friendsReader.Read()) { UserRelation friend = new UserRelation(core, friendsReader, UserLoadOptions.All); UnixTime tz = new UnixTime(core, friend.UserInfo.TimeZoneCode); DateTime dob = new DateTime(st.Year, friend.Profile.DateOfBirth.Month, friend.Profile.DateOfBirth.Day); long dobUt = tz.GetUnixTimeStamp(dob); if ((dobUt >= startTimeRaw && dobUt <= endTimeRaw) || (dobUt + 24 * 60 * 60 - 1 >= startTimeRaw && dobUt + 24 * 60 * 60 - 1 <= endTimeRaw)) { friends.Add(friend); } } friendsReader.Close(); friendsReader.Dispose(); return friends; }